# ProjectedDeviceController

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

*** ** * ** ***


```
@ExperimentalProjectedApi
class ProjectedDeviceController : AutoCloseable
```

<br />

*** ** * ** ***

Controller for the Projected device.

Use `https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController#create(android.content.Context)` to create an instance of this class. Call `https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController#close()` when finished with this instance to release resources.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController.Capability` Represents an intrinsic piece of functionality of a Projected device, i.e., what it is capable of. |

| ### Public companion functions |
|---|---|
| `suspend https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController#create(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` Connects to the service providing features for Projected devices and returns the `https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController` when the connection is established. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController#addBatteryStateChangedListener(kotlin.coroutines.CoroutineContext,kotlin.Function1)( context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html, listener: (https://developer.android.com/reference/kotlin/androidx/xr/projected/BatteryState) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Adds a listener for battery state changes. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController#close()()` Releases resources, unregistering any active listeners. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController#removeBatteryStateChangedListener(kotlin.Function1)(listener: (https://developer.android.com/reference/kotlin/androidx/xr/projected/BatteryState) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Removes a previously added listener. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/media/AudioDeviceInfo.html>` | `https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController#audioDevices()` Returns the list of `https://developer.android.com/reference/android/media/AudioDeviceInfo.html` objects associated with the projected device. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController.Capability>` | `https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController#capabilities()` The capabilities of the Projected device. |

## Public companion functions

### create

```
@RequiresApi(value = 34)
suspend fun create(context: Context): ProjectedDeviceController
```

Connects to the service providing features for Projected devices and returns the `https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController` when the connection is established. The caller is responsible for calling `https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController#close()` on the returned instance when it's no longer needed to release all internal resources.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The context to use for binding to the service. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if the projected service is not found or binding is not permitted |

## Public functions

### addBatteryStateChangedListener

Added in [1.0.0-alpha14](https://developer.android.com/jetpack/androidx/releases/xr-projected#1.0.0-alpha14)

```
fun addBatteryStateChangedListener(
    context: CoroutineContext,
    listener: (BatteryState) -> Unit
): Unit
```

Adds a listener for battery state changes.

The `https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController#addBatteryStateChangedListener(kotlin.coroutines.CoroutineContext,kotlin.Function1)` lambda will be executed in a new coroutine launched within the provided `https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController#addBatteryStateChangedListener(kotlin.coroutines.CoroutineContext,kotlin.Function1)`. The listener will be automatically unregistered when the `https://developer.android.com/reference/kotlin/androidx/xr/projected/ProjectedDeviceController#addBatteryStateChangedListener(kotlin.coroutines.CoroutineContext,kotlin.Function1)`'s `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html` is canceled.

### close

Added in [1.0.0-alpha14](https://developer.android.com/jetpack/androidx/releases/xr-projected#1.0.0-alpha14)

```
open fun close(): Unit
```

Releases resources, unregistering any active listeners. This instance should not be used after calling close.

### removeBatteryStateChangedListener

Added in [1.0.0-alpha14](https://developer.android.com/jetpack/androidx/releases/xr-projected#1.0.0-alpha14)

```
fun removeBatteryStateChangedListener(listener: (BatteryState) -> Unit): Unit
```

Removes a previously added listener. Note: Listeners are also automatically removed when their associated CoroutineScope is canceled.

## Public properties

### audioDevices

Added in [1.0.0-alpha14](https://developer.android.com/jetpack/androidx/releases/xr-projected#1.0.0-alpha14)

```
val audioDevices: List<AudioDeviceInfo>
```

Returns the list of `https://developer.android.com/reference/android/media/AudioDeviceInfo.html` objects associated with the projected device.

### capabilities

Added in [1.0.0-alpha14](https://developer.android.com/jetpack/androidx/releases/xr-projected#1.0.0-alpha14)

```
val capabilities: Set<ProjectedDeviceController.Capability>
```

The capabilities of the Projected device.

These capabilities represent intrinsic functionality of the device that will not change over the lifetime of the device, for example, whether the device is capable of showing a visual user interface at all, regardless of whether the screen is currently on or off.