UiModeManager

Kotlin | Java

public class UiModeManager

extends Object

This class provides access to the system uimode services. These services allow applications to control UI modes of the device. It provides functionality to disable the car mode and it gives access to the night mode settings.

These facilities are built on top of the underlying Intent.ACTION_DOCK_EVENT broadcasts that are sent when the user physical places the device into and out of a dock. When that happens, the UiModeManager switches the system Configuration to the appropriate UI mode, sends broadcasts about the mode switch, and starts the corresponding mode activity if appropriate. See the broadcasts ACTION_ENTER_CAR_MODE and ACTION_ENTER_DESK_MODE for more information.

In addition, the user may manually switch the system to car mode without physically being in a dock. While in car mode -- whether by manual action from the user or being physically placed in a dock -- a notification is displayed allowing the user to exit dock mode. Thus the dock mode represented here may be different than the current state of the underlying dock event broadcast.

Summary

Constants int DISABLE_CAR_MODE_GO_HOME Flag for use with disableCarMode(int) : go to the normal home activity as part of the disable. int ENABLE_CAR_MODE_ALLOW_SLEEP Flag for use with enableCarMode(int) : allow sleep mode while in car mode. int ENABLE_CAR_MODE_GO_CAR_HOME Flag for use with enableCarMode(int) : go to the car home activity as part of the enable. int MODE_NIGHT_AUTO Constant for setNightMode(int) and getNightMode() : automatically switch night mode on and off based on the time. int MODE_NIGHT_CUSTOM Constant for setNightMode(int) and getNightMode() : automatically switch night mode on and off based on the time. int MODE_NIGHT_NO Constant for setNightMode(int) and getNightMode() : never run in night mode. int MODE_NIGHT_YES Constant for setNightMode(int) and getNightMode() : always run in night mode.

Fields public static String ACTION_ENTER_CAR_MODE Broadcast sent when the device's UI has switched to car mode, either by being placed in a car dock or explicit action of the user. public static String ACTION_ENTER_DESK_MODE Broadcast sent when the device's UI has switched to desk mode, by being placed in a desk dock. public static String ACTION_EXIT_CAR_MODE Broadcast sent when the device's UI has switch away from car mode back to normal mode. public static String ACTION_EXIT_DESK_MODE Broadcast sent when the device's UI has switched away from desk mode back to normal mode.

Public methods void disableCarMode(int flags) Turn off special mode if currently in car mode. void enableCarMode(int flags) Force device into car mode, like it had been placed in the car dock. int getCurrentModeType() Return the current running mode type. LocalTime getCustomNightModeEnd() Returns the time of the day Dark theme deactivates When night mode is MODE_NIGHT_CUSTOM , the system uses this time set to deactivate it automatically. LocalTime getCustomNightModeStart() Returns the time of the day Dark theme activates When night mode is MODE_NIGHT_CUSTOM , the system uses this time set to activate it automatically. int getNightMode() Returns the currently configured night mode. void setCustomNightModeEnd(LocalTime time) Sets the time of the day Dark theme deactivates When night mode is MODE_NIGHT_CUSTOM , the system uses this time set to deactivate it automatically. void setCustomNightModeStart(LocalTime time) Sets the time of the day Dark theme activates When night mode is MODE_NIGHT_CUSTOM , the system uses this time set to activate it automatically void setNightMode(int mode) Sets the system-wide night mode.

Inherited methods java.lang.Object From class Object clone() Creates and returns a copy of this object. boolean equals(Object obj) Indicates whether some other object is "equal to" this one. void finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. final Class<?> getClass() Returns the runtime class of this Object . int hashCode() Returns a hash code value for the object. final void notify() Wakes up a single thread that is waiting on this object's monitor. final void notifyAll() Wakes up all threads that are waiting on this object's monitor. String toString() Returns a string representation of the object. final void wait(long timeout, int nanos) Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed. final void wait(long timeout) Causes the current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed. final void wait() Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.

Constants

DISABLE_CAR_MODE_GO_HOME Added in API level 8 public static final int DISABLE_CAR_MODE_GO_HOME Flag for use with disableCarMode(int) : go to the normal home activity as part of the disable. Disabling this way ensures a clean transition between the current activity (in car mode) and the original home activity (which was typically last running without being in car mode). Constant Value: 1 (0x00000001)

ENABLE_CAR_MODE_ALLOW_SLEEP Added in API level 21 public static final int ENABLE_CAR_MODE_ALLOW_SLEEP Flag for use with enableCarMode(int) : allow sleep mode while in car mode. By default, when this flag is not set, the system may hold a full wake lock to keep the screen turned on and prevent the system from entering sleep mode while in car mode. Setting this flag disables such behavior and the system may enter sleep mode if there is no other user activity and no other wake lock held. Setting this flag can be relevant for a car dock application that does not require the screen kept on. Constant Value: 2 (0x00000002)

ENABLE_CAR_MODE_GO_CAR_HOME Added in API level 8 public static final int ENABLE_CAR_MODE_GO_CAR_HOME Flag for use with enableCarMode(int) : go to the car home activity as part of the enable. Enabling this way ensures a clean transition between the current activity (in non-car-mode) and the car home activity that will serve as home while in car mode. This will switch to the car home activity even if we are already in car mode. Constant Value: 1 (0x00000001)

MODE_NIGHT_AUTO Added in API level 8 public static final int MODE_NIGHT_AUTO Constant for setNightMode(int) and getNightMode() : automatically switch night mode on and off based on the time. Constant Value: 0 (0x00000000)

MODE_NIGHT_CUSTOM Added in API level 30 public static final int MODE_NIGHT_CUSTOM Constant for setNightMode(int) and getNightMode() : automatically switch night mode on and off based on the time. Constant Value: 3 (0x00000003)

MODE_NIGHT_NO Added in API level 8 public static final int MODE_NIGHT_NO Constant for setNightMode(int) and getNightMode() : never run in night mode. Constant Value: 1 (0x00000001)

MODE_NIGHT_YES Added in API level 8 public static final int MODE_NIGHT_YES Constant for setNightMode(int) and getNightMode() : always run in night mode. Constant Value: 2 (0x00000002)

Fields

ACTION_ENTER_CAR_MODE Added in API level 8 public static String ACTION_ENTER_CAR_MODE Broadcast sent when the device's UI has switched to car mode, either by being placed in a car dock or explicit action of the user. After sending the broadcast, the system will start the intent Intent.ACTION_MAIN with category Intent.CATEGORY_CAR_DOCK to display the car UI, which typically what an application would implement to provide their own interface. However, applications can also monitor this Intent in order to be informed of mode changes or prevent the normal car UI from being displayed by setting the result of the broadcast to Activity#RESULT_CANCELED . This intent is broadcast when getCurrentModeType() transitions to Configuration#UI_MODE_TYPE_CAR from some other ui mode.

ACTION_ENTER_DESK_MODE Added in API level 8 public static String ACTION_ENTER_DESK_MODE Broadcast sent when the device's UI has switched to desk mode, by being placed in a desk dock. After sending the broadcast, the system will start the intent Intent.ACTION_MAIN with category Intent.CATEGORY_DESK_DOCK to display the desk UI, which typically what an application would implement to provide their own interface. However, applications can also monitor this Intent in order to be informed of mode changes or prevent the normal desk UI from being displayed by setting the result of the broadcast to Activity#RESULT_CANCELED .

ACTION_EXIT_CAR_MODE Added in API level 8 public static String ACTION_EXIT_CAR_MODE Broadcast sent when the device's UI has switch away from car mode back to normal mode. Typically used by a car mode app, to dismiss itself when the user exits car mode. This intent is broadcast when getCurrentModeType() transitions from Configuration#UI_MODE_TYPE_CAR to some other ui mode.

ACTION_EXIT_DESK_MODE Added in API level 8 public static String ACTION_EXIT_DESK_MODE Broadcast sent when the device's UI has switched away from desk mode back to normal mode. Typically used by a desk mode app, to dismiss itself when the user exits desk mode.

Public methods

disableCarMode Added in API level 8 public void disableCarMode (int flags) Turn off special mode if currently in car mode. Parameters flags int : One of the disable car mode flags. Value is DISABLE_CAR_MODE_GO_HOME

enableCarMode Added in API level 8 public void enableCarMode (int flags) Force device into car mode, like it had been placed in the car dock. This will cause the device to switch to the car home UI as part of the mode switch. Parameters flags int : Must be 0.

getCustomNightModeEnd Added in API level 30 public LocalTime getCustomNightModeEnd () Returns the time of the day Dark theme deactivates When night mode is MODE_NIGHT_CUSTOM , the system uses this time set to deactivate it automatically. Returns LocalTime This value cannot be null .

getCustomNightModeStart Added in API level 30 public LocalTime getCustomNightModeStart () Returns the time of the day Dark theme activates When night mode is MODE_NIGHT_CUSTOM , the system uses this time set to activate it automatically. Returns LocalTime This value cannot be null .

setCustomNightModeEnd Added in API level 30 public void setCustomNightModeEnd (LocalTime time) Sets the time of the day Dark theme deactivates When night mode is MODE_NIGHT_CUSTOM , the system uses this time set to deactivate it automatically. Parameters time LocalTime : The time of the day Dark theme should deactivate This value cannot be null .

setCustomNightModeStart Added in API level 30 public void setCustomNightModeStart (LocalTime time) Sets the time of the day Dark theme activates When night mode is MODE_NIGHT_CUSTOM , the system uses this time set to activate it automatically Parameters time LocalTime : The time of the day Dark theme should activate This value cannot be null .