# androidx.wear.ambient

*** ** * ** ***

## Interfaces

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver` | Interface for LifecycleObservers which are used to add ambient mode support to activities on Wearable devices. |
| `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver.AmbientLifecycleCallback` | Callback to receive ambient mode state changes. |
| `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientMode.AmbientCallbackProvider` | **This interface is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientModeSupport.AmbientCallbackProvider` | **This interface is deprecated.** Deprecated in Java |

## Classes

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver.AmbientDetails` | Details about ambient mode support on the current device, passed to `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver.AmbientLifecycleCallback#onEnterAmbient(androidx.wear.ambient.AmbientLifecycleObserver.AmbientDetails)`. |
| `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientMode` | **This class is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver` instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientMode.AmbientCallback` | **This class is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientMode.AmbientController` | **This class is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientModeSupport` | **This class is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver` instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientModeSupport.AmbientCallback` | **This class is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientModeSupport.AmbientController` | **This class is deprecated.** Deprecated in Java |

## Top-level functions summary

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver` | `https://developer.android.com/reference/kotlin/androidx/wear/ambient/package-summary#AmbientLifecycleObserver(android.app.Activity,androidx.wear.ambient.AmbientLifecycleObserver.AmbientLifecycleCallback)( activity: https://developer.android.com/reference/android/app/Activity.html, callbacks: https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver.AmbientLifecycleCallback )` Create a new `https://developer.android.com/reference/kotlin/androidx/wear/ambient/package-summary#AmbientLifecycleObserver(android.app.Activity,androidx.wear.ambient.AmbientLifecycleObserver.AmbientLifecycleCallback)` for use on a real device. |
| `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver` | `https://developer.android.com/reference/kotlin/androidx/wear/ambient/package-summary#AmbientLifecycleObserver(android.app.Activity,java.util.concurrent.Executor,androidx.wear.ambient.AmbientLifecycleObserver.AmbientLifecycleCallback)( activity: https://developer.android.com/reference/android/app/Activity.html, callbackExecutor: https://developer.android.com/reference/java/util/concurrent/Executor.html, callbacks: https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver.AmbientLifecycleCallback )` Create a new `https://developer.android.com/reference/kotlin/androidx/wear/ambient/package-summary#AmbientLifecycleObserver(android.app.Activity,java.util.concurrent.Executor,androidx.wear.ambient.AmbientLifecycleObserver.AmbientLifecycleCallback)` for use on a real device. |

## Top-level functions

### AmbientLifecycleObserver

Artifact: [androidx.wear:wear](https://developer.android.com/jetpack/androidx/releases/wear) [View Source](https://cs.android.com/search?q=file:androidx/wear/ambient/AmbientLifecycleObserver.kt+function:AmbientLifecycleObserver) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear#1.3.0)

```
fun AmbientLifecycleObserver(
    activity: Activity,
    callbacks: AmbientLifecycleObserver.AmbientLifecycleCallback
): AmbientLifecycleObserver
```

Create a new `https://developer.android.com/reference/kotlin/androidx/wear/ambient/package-summary#AmbientLifecycleObserver(android.app.Activity,androidx.wear.ambient.AmbientLifecycleObserver.AmbientLifecycleCallback)` for use on a real device.

Applications which wish to show layouts in ambient mode should attach the returned observer to their activities or fragments, passing in a set of callback to be notified about ambient state. In addition, the app needs to declare that it uses the `https://developer.android.com/reference/android/Manifest.permission.html#WAKE_LOCK` permission in its manifest.

The created `https://developer.android.com/reference/kotlin/androidx/wear/ambient/package-summary#AmbientLifecycleObserver(android.app.Activity,androidx.wear.ambient.AmbientLifecycleObserver.AmbientLifecycleCallback)` can also be used to query whether the device is in ambient mode.

As an example of how to use this class, see the following example:

```kotlin
class MyActivity : ComponentActivity() {
    private val callbacks = object : AmbientLifecycleObserver.AmbientLifecycleCallback {
        // ...
    }

    private val ambientObserver = AmbientLifecycleObserver(this, callbacks)

    override fun onCreate(savedInstanceState: Bundle) {
        super.onCreate(savedInstanceState)
        lifecycle.addObserver(ambientObserver)
    }
}
```

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html` | The activity that this observer is being attached to. |
| `callbacks: https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver.AmbientLifecycleCallback` | An instance of `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver.AmbientLifecycleCallback`, used to notify the observer about changes to the ambient state. |

### AmbientLifecycleObserver

Artifact: [androidx.wear:wear](https://developer.android.com/jetpack/androidx/releases/wear) [View Source](https://cs.android.com/search?q=file:androidx/wear/ambient/AmbientLifecycleObserver.kt+function:AmbientLifecycleObserver) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear#1.3.0)

```
fun AmbientLifecycleObserver(
    activity: Activity,
    callbackExecutor: Executor,
    callbacks: AmbientLifecycleObserver.AmbientLifecycleCallback
): AmbientLifecycleObserver
```

Create a new `https://developer.android.com/reference/kotlin/androidx/wear/ambient/package-summary#AmbientLifecycleObserver(android.app.Activity,java.util.concurrent.Executor,androidx.wear.ambient.AmbientLifecycleObserver.AmbientLifecycleCallback)` for use on a real device.

Applications which wish to show layouts in ambient mode should attach the returned observer to their activities or fragments, passing in a set of callback to be notified about ambient state. In addition, the app needs to declare that it uses the `https://developer.android.com/reference/android/Manifest.permission.html#WAKE_LOCK` permission in its manifest.

The created `https://developer.android.com/reference/kotlin/androidx/wear/ambient/package-summary#AmbientLifecycleObserver(android.app.Activity,java.util.concurrent.Executor,androidx.wear.ambient.AmbientLifecycleObserver.AmbientLifecycleCallback)` can also be used to query whether the device is in ambient mode.

As an example of how to use this class, see the following example:

```kotlin
class MyActivity : ComponentActivity() {
    private val callbacks = object : AmbientLifecycleObserver.AmbientLifecycleCallback {
        // ...
    }

    private val ambientObserver = AmbientLifecycleObserver(this, mainExecutor, callbacks)

    override fun onCreate(savedInstanceState: Bundle) {
        super.onCreate(savedInstanceState)
        lifecycle.addObserver(ambientObserver)
    }
}
```

If the observer is registered while the device is in ambient mode, the registered callback will immediately receive a call to `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver.AmbientLifecycleCallback#onEnterAmbient(androidx.wear.ambient.AmbientLifecycleObserver.AmbientDetails)`. If the device is in active mode, the callbacks will be registered, and `onEnterAmbient` will be called when the device next enters ambient mode.

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html` | The activity that this observer is being attached to. |
| `callbackExecutor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | The executor to run the provided callbacks on. |
| `callbacks: https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver.AmbientLifecycleCallback` | An instance of `https://developer.android.com/reference/kotlin/androidx/wear/ambient/AmbientLifecycleObserver.AmbientLifecycleCallback`, used to notify the observer about changes to the ambient state. |