RequiresSpatialApi


@Retention(value = AnnotationRetention.RUNTIME)
@Target(allowedTargets = [AnnotationTarget.FUNCTIONAnnotationTarget.PROPERTYAnnotationTarget.CLASS])
public annotation RequiresSpatialApi


Denotes that the annotated element should only be called on devices that support a given Spatial API version.

The Spatial API version required by an element is specified by the value parameter. The value should be one of the constants from androidx.xr.runtime.SpatialApiVersions.

To ensure that an API is available at runtime, applications should check the current Spatial API version by querying 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:


    

(SpatialApiVersions.SPATIAL_API_V2) fun newApiForV2() { // ... }

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

Summary

Public constructors

RequiresSpatialApi(int value)

Public methods

final int

The minimum Spatial API version required.

Public constructors

RequiresSpatialApi

Added in 1.0.0-alpha11
public RequiresSpatialApi(int value)

Public methods

getValue

public final int getValue()

The minimum Spatial API version required. The value should be one of the constants from androidx.xr.runtime.SpatialApiVersions.