Skip to content

Most visited

Recently visited

navigation
added in version 27.0.0
belongs to Maven artifact com.android.support:wear:27.0.0

AmbientMode

public final class AmbientMode
extends Fragment

java.lang.Object
   ↳ android.app.Fragment
     ↳ android.support.wear.ambient.AmbientMode


Use this as a headless Fragment to add ambient support to an Activity on Wearable devices.

The application that uses this should add the WAKE_LOCK permission to its manifest.

The primary entry point for this code is the attachAmbientSupport(Activity) method. It should be called with an Activity as an argument and that Activity will then be able to receive ambient lifecycle events through an AmbientMode.AmbientCallback. The Activity will also receive a AmbientMode.AmbientController object from the attachment which can be used to query the current status of the ambient mode, or toggle simple settings. An example of how to attach AmbientMode to your Activity and use the AmbientMode.AmbientController can be found below:

AmbientMode.AmbientController controller = AmbientMode.attachAmbientSupport(this);
     controller.setAutoResumeEnabled(true);
 

Summary

Nested classes

class AmbientMode.AmbientCallback

Callback to receive ambient mode state changes. 

interface AmbientMode.AmbientCallbackProvider

Interface for any Activity that wishes to implement Ambient Mode. 

class AmbientMode.AmbientController

A class for interacting with the ambient mode on a wearable device. 

Constants

String EXTRA_BURN_IN_PROTECTION

Property in bundle passed to AmbientCallback#onEnterAmbient(Bundle) to indicate whether burn-in protection is required.

String EXTRA_LOWBIT_AMBIENT

Property in bundle passed to AmbientCallback#onEnterAmbient(Bundle) to indicate whether the device has low-bit ambient mode.

String FRAGMENT_TAG

Fragment tag used by default when adding AmbientMode to add ambient support to an Activity.

Inherited constants

From interface android.content.ComponentCallbacks2

Public constructors

AmbientMode()

Constructor

Public methods

static <T extends Activity & AmbientMode.AmbientCallbackProvider> AmbientMode.AmbientController attachAmbientSupport(T activity)

Attach ambient support to the given activity.

void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)
void onAttach(Context context)
void onCreate(Bundle savedInstanceState)
void onDestroy()
void onDetach()
void onPause()
void onResume()
void onStop()

Inherited methods

From class android.app.Fragment
From class java.lang.Object
From interface android.content.ComponentCallbacks2
From interface android.view.View.OnCreateContextMenuListener
From interface android.content.ComponentCallbacks

Constants

EXTRA_BURN_IN_PROTECTION

added in version 27.0.0
String EXTRA_BURN_IN_PROTECTION

Property in bundle passed to AmbientCallback#onEnterAmbient(Bundle) to indicate whether burn-in protection is required. When this property is set to true, views must be shifted around periodically in ambient mode. To ensure that content isn't shifted off the screen, avoid placing content within 10 pixels of the edge of the screen. Activities should also avoid solid white areas to prevent pixel burn-in. Both of these requirements only apply in ambient mode, and only when this property is set to true.

Constant Value: "com.google.android.wearable.compat.extra.BURN_IN_PROTECTION"

EXTRA_LOWBIT_AMBIENT

added in version 27.0.0
String EXTRA_LOWBIT_AMBIENT

Property in bundle passed to AmbientCallback#onEnterAmbient(Bundle) to indicate whether the device has low-bit ambient mode. When this property is set to true, the screen supports fewer bits for each color in ambient mode. In this case, activities should disable anti-aliasing in ambient mode.

Constant Value: "com.google.android.wearable.compat.extra.LOWBIT_AMBIENT"

FRAGMENT_TAG

added in version 27.0.0
String FRAGMENT_TAG

Fragment tag used by default when adding AmbientMode to add ambient support to an Activity.

Constant Value: "android.support.wearable.ambient.AmbientMode"

Public constructors

AmbientMode

added in version 27.0.0
AmbientMode ()

Constructor

Public methods

attachAmbientSupport

added in version 27.0.0
AmbientMode.AmbientController attachAmbientSupport (T activity)

Attach ambient support to the given activity.

Parameters
activity T: the activity to attach ambient support to. This activity has to also implement AmbientMode.AmbientCallbackProvider

Returns
AmbientMode.AmbientController the associated AmbientMode.AmbientController which can be used to query the state of ambient mode and toggle simple settings related to it.

dump

void dump (String prefix, 
                FileDescriptor fd, 
                PrintWriter writer, 
                String[] args)

Parameters
prefix String

fd FileDescriptor

writer PrintWriter

args String

onAttach

void onAttach (Context context)

Parameters
context Context

onCreate

void onCreate (Bundle savedInstanceState)

Parameters
savedInstanceState Bundle

onDestroy

void onDestroy ()

onDetach

void onDetach ()

onPause

void onPause ()

onResume

void onResume ()

onStop

void onStop ()

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)