<br />


Applicable XR devices This guidance helps you build experiences for these types of XR devices. [Learn about XR device types →](https://developer.android.com/develop/xr/devices.md.txt) ![](https://developer.android.com/static/images/develop/xr/xr-headsets-icon.svg) XR Headsets [](https://developer.android.com/develop/xr/devices.md.txt#xr-headsets) ![](https://developer.android.com/static/images/develop/xr/xr-glasses-icon.svg) Wired XR Glasses [](https://developer.android.com/develop/xr/devices.md.txt#xr-glasses) [Learn about XR device types →](https://developer.android.com/develop/xr/devices.md.txt)

<br />

With ARCore for Jetpack XR, your app can retrieve a device's *pose*: the
orientation (pitch, yaw, roll) and a position (X, Y, Z) of the device relative
to the world origin.

> [!NOTE]
> **Note:** The accuracy of the positional data varies depending on the sensors and capabilities of the user's device.

Use this information to render digital content in the real world, or convert the
device pose to a geospatial pose to generate location-aware data.

## Access a session

Access device pose information through a Jetpack XR Runtime [`Session`](https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session.md.txt),
which your [app must create](https://developer.android.com/develop/xr/jetpack-xr-sdk/arcore.md.txt#access-session-runtime).

## Configure the session

Device pose information is not enabled by default on XR sessions. To enable your
app to retrieve device pose information, configure the session and set the
[`DeviceTrackingMode.SPATIAL`](https://developer.android.com/reference/kotlin/androidx/xr/runtime/DeviceTrackingMode.md.txt#SPATIAL()) mode:


```kotlin
// Define the configuration object to enable tracking device pose.
val newConfig = Config.Builder(session.config)
    .setDeviceTracking(DeviceTrackingMode.SPATIAL)
    .build()
// Apply the configuration to the session.
try {
    when (val configResult = session.configure(newConfig)) {
        is SessionConfigureSuccess -> {
            // The session is now configured to track the device's pose.
        }
        else -> {
            // Catch-all for other configuration errors returned using the result class.
        }
    }
} catch (e: UnsupportedOperationException) {
    // Handle configuration failure. For example, if the specific mode is not supported on the current device or API version.
}
```

<br />

Not all XR devices support the `DeviceTrackingMode.SPATIAL` mode. If
[`Session.configure()`](https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session.md.txt#configure(androidx.xr.runtime.Config)) succeeds, the device supports this mode.

> [!NOTE]
> **Note:** Enabling this mode on immersive devices requires the `android.permission.HEAD_TRACKING` [runtime permission](https://developer.android.com/guide/topics/permissions/overview.md.txt#runtime) to be granted to your app.

## Obtain the device pose

After you've configured the session, you can obtain the device's pose within the
AR coordinate system using the [`ArDevice`](https://developer.android.com/reference/kotlin/androidx/xr/arcore/ArDevice.md.txt) object:


```kotlin
// Get the ArDevice instance
val arDevice = ArDevice.getInstance(session)
// There are two ways to get the device pose.

// 1. Get the current device pose once.
// This is the device's position and orientation relative to the tracking origin.
val devicePose = arDevice.state.value.devicePose
processDevicePose(devicePose)

// 2. Continuously receive updates for the device pose.
// `collect` is a suspending function that will run indefinitely and process new poses.
arDevice.state.collect { state ->
    processDevicePose(state.devicePose)
}
```

<br />

## Get the device pose's translation and rotation

The device `Pose` represents the device's position (translation) and orientation
(rotation) relative to the tracking origin. Use this information in your app to
enhance your app's experience:

- **Provide positionally accurate navigation instructions**: Use positional data to help a user orient themselves and navigate their surroundings with help from overlaid digital content.


```kotlin
fun processDevicePose(pose: Pose) {
    // Extract Translation and Rotation
    val translation = pose.translation // Vector3(x, y, z)
    val rotation = pose.rotation // Quaternion (x, y, z, w)
    TODO(/* Use the translation and rotation in your app. */)
}
```

<br />