# RequiresExtension

Artifact: [androidx.annotation:annotation](https://developer.android.com/jetpack/androidx/releases/annotation) [View Source](https://cs.android.com/search?q=file:androidx/annotation/RequiresExtension.jvm.kt+class:androidx.annotation.RequiresExtension) Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/annotation#1.6.0)

*** ** * ** ***


```
@MustBeDocumented
@Retention(value = AnnotationRetention.BINARY)
@Target(allowedTargets = [AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FIELD, AnnotationTarget.FILE])
@Target(value = [ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE])
@Repeatable
public annotation RequiresExtension
```

<br />

*** ** * ** ***

Denotes that the annotated element should only be called if the given extension is at least the given version.

This annotation is repeatable, and if specified multiple times, you are required to have one of (not all of) the specified extension versions.

Example:

```
@RequiresExtension(extension = Build.VERSION_CODES.R, version = 3)
fun methodUsingApisFromR() { ... }
```

For the special case of `https://developer.android.com/reference/androidx/annotation/RequiresExtension#extension()` == 0, you can instead use the `https://developer.android.com/reference/androidx/annotation/RequiresApi` annotation; `@RequiresApi(30)` is equivalent to `@RequiresExtension(extension=0, version=30)`.

## Summary

| ### Public methods |
|---|---|
| `final int` | `https://developer.android.com/reference/androidx/annotation/RequiresExtension#getExtension()()` The extension SDK ID. |
| `final int` | `https://developer.android.com/reference/androidx/annotation/RequiresExtension#getVersion()()` The minimum version to require |

## Public methods

### getExtension

```
public final int getExtension()
```

The extension SDK ID. This corresponds to the extension id's allowed by `https://developer.android.com/reference/android/os/ext/SdkExtensions.html#getExtensionVersion(int)`, and for id values less than 1_000_000 is one of the `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html`.

### getVersion

```
public final int getVersion()
```

The minimum version to require