Spatial capabilities can vary across devices and change as users interact with your app or the system. They can even be changed by your app itself—for example, moving into Home Space or Full Space. To avoid issues, your app needs to check for spatial capabilities to determine which APIs are supported in the current environment.
Check for spatial capabilities using Jetpack Compose for XR
Jetpack Compose for XR creates a Composition Local for checking spatial capabilities. Use this to check whether spatial UI, spatial audio, environments, passthrough, or 3D content is enabled.
You can use LocalSpatialCapabilities.current to check if the following
spatial capabilities are currently available:
isSpatialUiEnabled: Indicates whether the application may create spatial UI elements (for example,SpatialPanel).isContent3dEnabled: Indicates whether the application may create 3D objects.isAppEnvironmentEnabled: Indicates whether the application may set the environment.isPassthroughControlEnabled: Indicates whether the application may control the passthrough state.isSpatialAudioEnabled: Indicates whether the application may use spatial audio.
The following example shows how to check if spatial UI is enabled:
if (LocalSpatialCapabilities.current.isSpatialUiEnabled) { Subspace { SpatialPanel( modifier = SubspaceModifier .width(1488.dp) .fillMaxHeight() ) { AppContent() } } } else { AppContent() }
Check for spatial capabilities using SceneCore
When using the SceneCore library, you'll have to create a session. Once
the session is created, use spatialCapabilities from the session's
scene to query which spatial capabilities are currently available.
SPATIAL_3D_CONTENT: The activity can create 3D contents.APP_ENVIRONMENT: The activity can set its own environment.EMBED_ACTIVITY: The activity can spatially embed another activity.PASSTHROUGH_CONTROL: The activity can enable or disable passthrough.SPATIAL_AUDIO: The activity can use spatial audio.SPATIAL_UI: The activity can spatialize itself (for example, adding a spatial panel).
You can also choose to subscribe to a callback,
addSpatialCapabilitiesChangedListener that notifies you when spatial
capabilities have changed.
// Example 1: check if enabling passthrough mode is allowed if (xrSession.scene.spatialCapabilities.contains( SpatialCapability.PASSTHROUGH_CONTROL ) ) { xrSession.scene.spatialEnvironment.preferredPassthroughOpacity = 1f } // Example 2: multiple capability flags can be checked simultaneously: if (xrSession.scene.spatialCapabilities.contains(SpatialCapability.PASSTHROUGH_CONTROL) && xrSession.scene.spatialCapabilities.contains(SpatialCapability.SPATIAL_3D_CONTENT) ) { // ... }
Use blend mode to check the device's display capabilities
On Android XR, XR headsets and wired XR glasses have varying hardware
capabilities, especially concerning their display type. You might need to adapt
the colors of your app's UI and rendered objects to maximize visibility, which
might be influenced by the display type and the preferred blend mode employed by the
device. The DisplayBlendMode API provides the device's blend mode
capability for rendering. Use this API to determine how virtual content is
added to the real world.
Here are some of the blend mode types to be aware of:
ADDITIVE: Virtual content is added to the real world by adding the pixel values for each of Red, Green, and Blue components. Alpha is ignored, and black pixels appear transparent.ALPHA_BLEND: Virtual content is added to the real world by alpha blending the pixel values based on the Alpha component.NO_DISPLAY: Blending is not supported on the device.
Use XrDevice.getCurrentDevice(session).getPreferredDisplayBlendMode() from the
Jetpack XR Runtime library to check what type of blend mode is being used
and make adjustments as needed.
See also
- Create a session
- Transition between HSM and FSM
- Add spatial environments to your app
- Add 3D models to your app