# RequiresSpatialApi

Artifact: [androidx.xr.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/xr-runtime) [View Source](https://cs.android.com/search?q=file:androidx/xr/runtime/SpatialApi.kt+class:androidx.xr.runtime.RequiresSpatialApi) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

*** ** * ** ***


```
@Retention(value = AnnotationRetention.RUNTIME)
@Target(allowedTargets = [AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.CLASS, AnnotationTarget.CONSTRUCTOR])
public annotation RequiresSpatialApi
```

<br />

*** ** * ** ***

Annotates elements that require a specific Spatial API version.

The Spatial API version required by an element is specified by the `https://developer.android.com/reference/androidx/xr/runtime/RequiresSpatialApi#value()` parameter. The value should be one of the constants from `https://developer.android.com/reference/androidx/xr/runtime/SpatialApiVersions`.

To ensure that an API is available at runtime, applications should check the current Spatial API version by querying `https://developer.android.com/reference/androidx/xr/runtime/SpatialApiVersionHelper#spatialApiVersion()`. This check is crucial for preventing runtime errors when an application is running on a device that does not support the required API version.

Example of annotating an API and performing a runtime check:

```
@RequiresSpatialApi(SpatialApiVersions.SPATIAL_API_V2)
fun newApiForV2() {
    // ...
}

fun callNewApi() {
    if (SpatialApiVersionHelper.spatialApiVersion >= SpatialApiVersions.SPATIAL_API_V2) {
        newApiForV2()
    } else {
        // Handle the case where the API is not available.
    }
}
```

## Summary

| ### Public methods |
|---|---|
| `final int` | `https://developer.android.com/reference/androidx/xr/runtime/RequiresSpatialApi#getValue()()` The minimum Spatial API version required. |

## Public methods

### getValue

```
public final int getValue()
```

The minimum Spatial API version required. The value should be one of the constants from `https://developer.android.com/reference/androidx/xr/runtime/SpatialApiVersions`.