androidx.wear.ambient
Interfaces
AmbientLifecycleObserver |
Interface for LifecycleObservers which are used to add ambient mode support to activities on Wearable devices. |
AmbientLifecycleObserver.AmbientLifecycleCallback |
Callback to receive ambient mode state changes. |
AmbientMode.AmbientCallbackProvider |
Interface for any |
AmbientModeSupport.AmbientCallbackProvider |
Interface for any |
Classes
AmbientLifecycleObserver.AmbientDetails |
Details about ambient mode support on the current device, passed to |
AmbientMode |
This class is deprecated. Use |
AmbientMode.AmbientCallback |
Callback to receive ambient mode state changes. |
AmbientMode.AmbientController |
A class for interacting with the ambient mode on a wearable device. |
AmbientModeSupport |
This class is deprecated. Use |
AmbientModeSupport.AmbientCallback |
Callback to receive ambient mode state changes. |
AmbientModeSupport.AmbientController |
A class for interacting with the ambient mode on a wearable device. |
Top-level functions summary
AmbientLifecycleObserver |
AmbientLifecycleObserver(Create a new |
AmbientLifecycleObserver |
AmbientLifecycleObserver(Create a new |
Top-level functions
AmbientLifecycleObserver
fun AmbientLifecycleObserver(
activity: Activity,
callbacks: AmbientLifecycleObserver.AmbientLifecycleCallback
): AmbientLifecycleObserver
Create a new AmbientLifecycleObserver 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 android.Manifest.permission.WAKE_LOCK permission in its manifest.
The created AmbientLifecycleObserver 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:
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: Activity |
The activity that this observer is being attached to. |
callbacks: AmbientLifecycleObserver.AmbientLifecycleCallback |
An instance of |
AmbientLifecycleObserver
fun AmbientLifecycleObserver(
activity: Activity,
callbackExecutor: Executor,
callbacks: AmbientLifecycleObserver.AmbientLifecycleCallback
): AmbientLifecycleObserver
Create a new AmbientLifecycleObserver 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 android.Manifest.permission.WAKE_LOCK permission in its manifest.
The created AmbientLifecycleObserver 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:
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 AmbientLifecycleObserver.AmbientLifecycleCallback.onEnterAmbient. 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: Activity |
The activity that this observer is being attached to. |
callbackExecutor: Executor |
The executor to run the provided callbacks on. |
callbacks: AmbientLifecycleObserver.AmbientLifecycleCallback |
An instance of |