public class UiModeManager extends Object
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.
You do not instantiate this class directly; instead, retrieve it through
Context.getSystemService(Context.UI_MODE_SERVICE)
.
Modifier and Type | Class and Description |
---|---|
static interface |
UiModeManager.NightMode |
Modifier and Type | Field and Description |
---|---|
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.
|
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.
|
static String |
ACTION_EXIT_CAR_MODE
Broadcast sent when the device's UI has switch away from car mode back
to normal mode.
|
static String |
ACTION_EXIT_DESK_MODE
Broadcast sent when the device's UI has switched away from desk mode back
to normal mode.
|
static int |
DISABLE_CAR_MODE_GO_HOME
Flag for use with
disableCarMode(int) : go to the normal
home activity as part of the disable. |
static int |
ENABLE_CAR_MODE_ALLOW_SLEEP
Flag for use with
enableCarMode(int) : allow sleep mode while in car mode. |
static int |
ENABLE_CAR_MODE_GO_CAR_HOME
Flag for use with
enableCarMode(int) : go to the car
home activity as part of the enable. |
static int |
MODE_NIGHT_AUTO
Constant for
setNightMode(int) and getNightMode() :
automatically switch night mode on and off based on the time. |
static int |
MODE_NIGHT_NO
Constant for
setNightMode(int) and getNightMode() :
never run in night mode. |
static int |
MODE_NIGHT_YES
Constant for
setNightMode(int) and getNightMode() :
always run in night mode. |
Modifier and Type | Method and Description |
---|---|
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.
|
int |
getNightMode()
Returns the currently configured night mode.
|
boolean |
isNightModeLocked()
Returns whether night mode is locked or not.
|
boolean |
isUiModeLocked() |
void |
setNightMode(int mode)
Sets the night mode.
|
public static String ACTION_ENTER_CAR_MODE
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
.public static String ACTION_EXIT_CAR_MODE
public static String ACTION_ENTER_DESK_MODE
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
.public static String ACTION_EXIT_DESK_MODE
public static final int MODE_NIGHT_AUTO
setNightMode(int)
and getNightMode()
:
automatically switch night mode on and off based on the time.public static final int MODE_NIGHT_NO
setNightMode(int)
and getNightMode()
:
never run in night mode.public static final int MODE_NIGHT_YES
setNightMode(int)
and getNightMode()
:
always run in night mode.public static final int ENABLE_CAR_MODE_GO_CAR_HOME
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.public static final int ENABLE_CAR_MODE_ALLOW_SLEEP
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.public static final int DISABLE_CAR_MODE_GO_HOME
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).public void enableCarMode(int flags)
flags
- Must be 0.public void disableCarMode(int flags)
flags
- May be 0 or DISABLE_CAR_MODE_GO_HOME
.public int getCurrentModeType()
Configuration.UI_MODE_TYPE_NORMAL
,
Configuration.UI_MODE_TYPE_DESK
,
Configuration.UI_MODE_TYPE_CAR
,
Configuration.UI_MODE_TYPE_TELEVISION
,
Configuration.UI_MODE_TYPE_APPLIANCE
, or
Configuration.UI_MODE_TYPE_WATCH
.public void setNightMode(int mode)
The mode can be one of:
MODE_NIGHT_NO
sets the device into
notnight
modeMODE_NIGHT_YES
sets the device into
night
modeMODE_NIGHT_AUTO
automatically switches between
night
and notnight
based on the device's current
location and certain other sensors
Note: On API 22 and below, changes to the night mode
are only effective when the car
or desk
mode is enabled on a
device. Starting in API 23, changes to night mode are always effective.
mode
- the night mode to setgetNightMode()
public int getNightMode()
May be one of:
MODE_NIGHT_NO
MODE_NIGHT_YES
MODE_NIGHT_AUTO
-1
on error-1
on errorsetNightMode(int)
public boolean isUiModeLocked()
enableCarMode(int)
will silently fail.public boolean isNightModeLocked()
When night mode is locked, only privileged system components may change night mode and calls from non-privileged applications to change night mode will fail silently.
true
if night mode is locked or false
otherwise