AmbientModeSupport
class AmbientModeSupport : Fragment
kotlin.Any | ||
↳ | androidx.fragment.app.Fragment | |
↳ | androidx.wear.ambient.AmbientModeSupport |
Use this as a headless Fragment to add ambient support to an Activity on Wearable devices.
The application that uses this should add the android.Manifest.permission#WAKE_LOCK
permission to its manifest.
The following describes the general use of this class:
Create a subclass of one of the FragmentActivity
classes and implement the AmbientCallbackProvider
interface. Override the AmbientCallbackProvider#getAmbientCallback()
method to provide the callbacks required for reacting to the ambient events from the Android system. If a valid AmbientCallback
is not provided (either no implementation of the AmbientCallbackProvider
interface, or returning null from AmbientCallbackProvider#getAmbientCallback()
), then ambient mode will NOT be enabled.
The primary entry point for this code is the attach(FragmentActivity)
method. It should be called with an FragmentActivity
as an argument and that FragmentActivity
will then be able to receive ambient lifecycle events through an AmbientCallback
. The FragmentActivity
will also receive a AmbientController
object from the attachment which can be used to query the current status of the ambient mode.
An example of how to implement the AmbientCallbackProvider
interface, attach AmbientModeSupport
to your FragmentActivity
and use the AmbientController
can be found below:
public class MyActivity extends FragmentActivity implements AmbientModeSupport.AmbientCallbackProvider { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState) ... AmbientModeSupport.AmbientController controller = AmbientModeSupport.attach(this); boolean isAmbient = controller.isAmbient(); } @Override AmbientModeSupport.AmbientCallback getAmbientCallback() { return new AmbientModeSupport.AmbientCallback() { public void onEnterAmbient(Bundle ambientDetails) {...} public void onExitAmbient(Bundle ambientDetails) {...} } } }
Summary
Nested classes | |
---|---|
abstract |
Callback to receive ambient mode state changes. |
abstract |
Interface for any |
A class for interacting with the ambient mode on a wearable device. |
Constants | |
---|---|
static String |
Property in bundle passed to |
static String |
Property in bundle passed to |
static String |
Fragment tag used by default when adding |
Public constructors | |
---|---|
<init>() Constructor |
Public methods | |
---|---|
static AmbientModeSupport.AmbientController! |
attach(activity: T) Attach ambient support to the given activity. |
Unit |
dump(prefix: String, fd: FileDescriptor?, writer: PrintWriter, args: Array<String!>?) |
Unit | |
Unit | |
Unit | |
Unit |
onDetach() |
Unit |
onPause() |
Unit |
onResume() |
Unit |
onStop() |
Inherited functions | |
---|---|