Check device capabilities at runtime for audio glasses and display glasses

Applicable XR devices
This guidance helps you build experiences for these types of XR devices.
Audio &
Display Glasses

Different types of audio glasses and display glasses have different capabilities. After planning how you'll support different types of AI devices, you can check for device capabilities at runtime to provide the best experience for a user's device.

Check whether a device has a display

Display glasses can show UIs built with Jetpack Compose Glimmer. The following example shows how to check whether a glasses device has a display:

// Check device capabilities
val projectedDeviceController = ProjectedDeviceController.create(this@GlassesMainActivity)
isVisualUiSupported = projectedDeviceController.capabilities.contains(CAPABILITY_VISUAL_UI)

React to display state changes

On display glasses, the display can time out or the user can turn off the display. To design activities that run whether the display is on or off, use addPresentationModeChangedListener to be notified when the display state changes. You can tune your activity for the appropriate amount of audio information depending on display state.

ProjectedDisplayController.create(activity).addPresentationModeChangedListener {
    presentationModeFlags ->

    val areVisualsOff = !presentationModeFlags.hasPresentationMode(VISUALS_ON)
}

Keep the display on

On display glasses, you can request that the system keep the screen on and prevent the screen from timing out using addLayoutParamsFlags.

var projectedDisplayController = ProjectedDisplayController.create(activity)

projectedDisplayController.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)