# UiModeManager

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Nested Classes](https://developer.android.com/reference/android/app/UiModeManager#nestedclasses)\|[Constants](https://developer.android.com/reference/android/app/UiModeManager#constants)\|[Fields](https://developer.android.com/reference/android/app/UiModeManager#lfields)\|[Methods](https://developer.android.com/reference/android/app/UiModeManager#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/app/UiModeManager#inhmethods)  

# UiModeManager

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/app/UiModeManager "View this page in Kotlin")\|Java

`
public


class
UiModeManager
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|---------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.app.UiModeManager |

<br />

*** ** * ** ***

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](https://developer.android.com/reference/android/content/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](https://developer.android.com/reference/android/content/res/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](https://developer.android.com/reference/android/app/UiModeManager#ACTION_ENTER_CAR_MODE)and[ACTION_ENTER_DESK_MODE](https://developer.android.com/reference/android/app/UiModeManager#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

|                                                                              ### Nested classes                                                                              ||
|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` interface` | [UiModeManager.ContrastChangeListener](https://developer.android.com/reference/android/app/UiModeManager.ContrastChangeListener) Listener for the UI contrast. |

|                                                                                                                                                                                              ### Constants                                                                                                                                                                                               ||
|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [DISABLE_CAR_MODE_GO_HOME](https://developer.android.com/reference/android/app/UiModeManager#DISABLE_CAR_MODE_GO_HOME) Flag for use with[disableCarMode(int)](https://developer.android.com/reference/android/app/UiModeManager#disableCarMode(int)): go to the normal home activity as part of the disable.                                                                                      |
| `int` | [ENABLE_CAR_MODE_ALLOW_SLEEP](https://developer.android.com/reference/android/app/UiModeManager#ENABLE_CAR_MODE_ALLOW_SLEEP) Flag for use with[enableCarMode(int)](https://developer.android.com/reference/android/app/UiModeManager#enableCarMode(int)): allow sleep mode while in car mode.                                                                                                     |
| `int` | [ENABLE_CAR_MODE_GO_CAR_HOME](https://developer.android.com/reference/android/app/UiModeManager#ENABLE_CAR_MODE_GO_CAR_HOME) Flag for use with[enableCarMode(int)](https://developer.android.com/reference/android/app/UiModeManager#enableCarMode(int)): go to the car home activity as part of the enable.                                                                                      |
| `int` | [MODE_NIGHT_AUTO](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_AUTO) Constant for[setNightMode(int)](https://developer.android.com/reference/android/app/UiModeManager#setNightMode(int))and[getNightMode()](https://developer.android.com/reference/android/app/UiModeManager#getNightMode()): automatically switch night mode on and off based on the time.     |
| `int` | [MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM) Constant for[setNightMode(int)](https://developer.android.com/reference/android/app/UiModeManager#setNightMode(int))and[getNightMode()](https://developer.android.com/reference/android/app/UiModeManager#getNightMode()): automatically switch night mode on and off based on the time. |
| `int` | [MODE_NIGHT_NO](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_NO) Constant for[setNightMode(int)](https://developer.android.com/reference/android/app/UiModeManager#setNightMode(int))and[getNightMode()](https://developer.android.com/reference/android/app/UiModeManager#getNightMode()): never run in night mode.                                              |
| `int` | [MODE_NIGHT_YES](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_YES) Constant for[setNightMode(int)](https://developer.android.com/reference/android/app/UiModeManager#setNightMode(int))and[getNightMode()](https://developer.android.com/reference/android/app/UiModeManager#getNightMode()): always run in night mode.                                           |

|                                                                                                                                                                ### Fields                                                                                                                                                                ||
|-------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` public static `[String](https://developer.android.com/reference/java/lang/String) | [ACTION_ENTER_CAR_MODE](https://developer.android.com/reference/android/app/UiModeManager#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](https://developer.android.com/reference/java/lang/String) | [ACTION_ENTER_DESK_MODE](https://developer.android.com/reference/android/app/UiModeManager#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](https://developer.android.com/reference/java/lang/String) | [ACTION_EXIT_CAR_MODE](https://developer.android.com/reference/android/app/UiModeManager#ACTION_EXIT_CAR_MODE) Broadcast sent when the device's UI has switch away from car mode back to normal mode.                                               |
| ` public static `[String](https://developer.android.com/reference/java/lang/String) | [ACTION_EXIT_DESK_MODE](https://developer.android.com/reference/android/app/UiModeManager#ACTION_EXIT_DESK_MODE) Broadcast sent when the device's UI has switched away from desk mode back to normal mode.                                          |

|                                                                                                                                                                                                                                                                                                                                  ### Public methods                                                                                                                                                                                                                                                                                                                                  ||
|-----------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`                                                                     | ` `[addContrastChangeListener](https://developer.android.com/reference/android/app/UiModeManager#addContrastChangeListener(java.util.concurrent.Executor,%20android.app.UiModeManager.ContrastChangeListener))`(`[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[UiModeManager.ContrastChangeListener](https://developer.android.com/reference/android/app/UiModeManager.ContrastChangeListener)` listener) ` Registers a[ContrastChangeListener](https://developer.android.com/reference/android/app/UiModeManager.ContrastChangeListener)for the user. |
| ` void`                                                                     | ` `[disableCarMode](https://developer.android.com/reference/android/app/UiModeManager#disableCarMode(int))`(int flags) ` Turn off special mode if currently in car mode.                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` void`                                                                     | ` `[enableCarMode](https://developer.android.com/reference/android/app/UiModeManager#enableCarMode(int))`(int flags) ` Force device into car mode, like it had been placed in the car dock.                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` float`                                                                    | ` `[getContrast](https://developer.android.com/reference/android/app/UiModeManager#getContrast())`() ` Returns the color contrast for the user.                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ` int`                                                                      | ` `[getCurrentModeType](https://developer.android.com/reference/android/app/UiModeManager#getCurrentModeType())`() ` Return the current running mode type.                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ` `[LocalTime](https://developer.android.com/reference/java/time/LocalTime) | ` `[getCustomNightModeEnd](https://developer.android.com/reference/android/app/UiModeManager#getCustomNightModeEnd())`() ` Returns the time of the day Dark theme deactivates When night mode is[MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM), the system uses this time set to deactivate it automatically.                                                                                                                                                                                                                                 |
| ` `[LocalTime](https://developer.android.com/reference/java/time/LocalTime) | ` `[getCustomNightModeStart](https://developer.android.com/reference/android/app/UiModeManager#getCustomNightModeStart())`() ` Returns the time of the day Dark theme activates When night mode is[MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM), the system uses this time set to activate it automatically.                                                                                                                                                                                                                                 |
| ` int`                                                                      | ` `[getNightMode](https://developer.android.com/reference/android/app/UiModeManager#getNightMode())`() ` Returns the currently configured night mode.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` void`                                                                     | ` `[removeContrastChangeListener](https://developer.android.com/reference/android/app/UiModeManager#removeContrastChangeListener(android.app.UiModeManager.ContrastChangeListener))`(`[UiModeManager.ContrastChangeListener](https://developer.android.com/reference/android/app/UiModeManager.ContrastChangeListener)` listener) ` Unregisters a[ContrastChangeListener](https://developer.android.com/reference/android/app/UiModeManager.ContrastChangeListener)for the user.                                                                                                                        |
| ` void`                                                                     | ` `[setApplicationNightMode](https://developer.android.com/reference/android/app/UiModeManager#setApplicationNightMode(int))`(int mode) ` Sets and persist the night mode for this application.                                                                                                                                                                                                                                                                                                                                                                                                         |
| ` void`                                                                     | ` `[setCustomNightModeEnd](https://developer.android.com/reference/android/app/UiModeManager#setCustomNightModeEnd(java.time.LocalTime))`(`[LocalTime](https://developer.android.com/reference/java/time/LocalTime)` time) ` Sets the time of the day Dark theme deactivates When night mode is[MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM), the system uses this time set to deactivate it automatically.                                                                                                                                  |
| ` void`                                                                     | ` `[setCustomNightModeStart](https://developer.android.com/reference/android/app/UiModeManager#setCustomNightModeStart(java.time.LocalTime))`(`[LocalTime](https://developer.android.com/reference/java/time/LocalTime)` time) ` Sets the time of the day Dark theme activates When night mode is[MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM), the system uses this time set to activate it automatically                                                                                                                                   |
| ` void`                                                                     | ` `[setNightMode](https://developer.android.com/reference/android/app/UiModeManager#setNightMode(int))`(int mode) ` Sets the system-wide night mode.                                                                                                                                                                                                                                                                                                                                                                                                                                                    |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Constants

### DISABLE_CAR_MODE_GO_HOME

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int DISABLE_CAR_MODE_GO_HOME
```

Flag for use with[disableCarMode(int)](https://developer.android.com/reference/android/app/UiModeManager#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).

<br />

Constant Value: 1 (0x00000001)  

### ENABLE_CAR_MODE_ALLOW_SLEEP

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int ENABLE_CAR_MODE_ALLOW_SLEEP
```

Flag for use with[enableCarMode(int)](https://developer.android.com/reference/android/app/UiModeManager#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.

<br />

Constant Value: 2 (0x00000002)  

### ENABLE_CAR_MODE_GO_CAR_HOME

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int ENABLE_CAR_MODE_GO_CAR_HOME
```

Flag for use with[enableCarMode(int)](https://developer.android.com/reference/android/app/UiModeManager#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.

<br />

Constant Value: 1 (0x00000001)  

### MODE_NIGHT_AUTO

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int MODE_NIGHT_AUTO
```

Constant for[setNightMode(int)](https://developer.android.com/reference/android/app/UiModeManager#setNightMode(int))and[getNightMode()](https://developer.android.com/reference/android/app/UiModeManager#getNightMode()): automatically switch night mode on and off based on the time.

<br />

Constant Value: 0 (0x00000000)  

### MODE_NIGHT_CUSTOM

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int MODE_NIGHT_CUSTOM
```

Constant for[setNightMode(int)](https://developer.android.com/reference/android/app/UiModeManager#setNightMode(int))and[getNightMode()](https://developer.android.com/reference/android/app/UiModeManager#getNightMode()): automatically switch night mode on and off based on the time.

<br />

Constant Value: 3 (0x00000003)  

### MODE_NIGHT_NO

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int MODE_NIGHT_NO
```

Constant for[setNightMode(int)](https://developer.android.com/reference/android/app/UiModeManager#setNightMode(int))and[getNightMode()](https://developer.android.com/reference/android/app/UiModeManager#getNightMode()): never run in night mode.

<br />

Constant Value: 1 (0x00000001)  

### MODE_NIGHT_YES

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int MODE_NIGHT_YES
```

Constant for[setNightMode(int)](https://developer.android.com/reference/android/app/UiModeManager#setNightMode(int))and[getNightMode()](https://developer.android.com/reference/android/app/UiModeManager#getNightMode()): always run in night mode.

<br />

Constant Value: 2 (0x00000002)

## Fields

### ACTION_ENTER_CAR_MODE

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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](https://developer.android.com/reference/android/content/Intent#ACTION_MAIN)with category[Intent.CATEGORY_CAR_DOCK](https://developer.android.com/reference/android/content/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](https://developer.android.com/reference/android/app/Activity#RESULT_CANCELED).

This intent is broadcast when[getCurrentModeType()](https://developer.android.com/reference/android/app/UiModeManager#getCurrentModeType())transitions to[Configuration.UI_MODE_TYPE_CAR](https://developer.android.com/reference/android/content/res/Configuration#UI_MODE_TYPE_CAR)from some other ui mode.

<br />

### ACTION_ENTER_DESK_MODE

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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](https://developer.android.com/reference/android/content/Intent#ACTION_MAIN)with category[Intent.CATEGORY_DESK_DOCK](https://developer.android.com/reference/android/content/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](https://developer.android.com/reference/android/app/Activity#RESULT_CANCELED).

<br />

### ACTION_EXIT_CAR_MODE

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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()](https://developer.android.com/reference/android/app/UiModeManager#getCurrentModeType())transitions from[Configuration.UI_MODE_TYPE_CAR](https://developer.android.com/reference/android/content/res/Configuration#UI_MODE_TYPE_CAR)to some other ui mode.

<br />

### ACTION_EXIT_DESK_MODE

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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.

<br />

## Public methods

### addContrastChangeListener

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void addContrastChangeListener (Executor executor, 
                UiModeManager.ContrastChangeListener listener)
```

Registers a[ContrastChangeListener](https://developer.android.com/reference/android/app/UiModeManager.ContrastChangeListener)for the user.

<br />

|                                                                                                                                                                                                                                                                                                                            Parameters                                                                                                                                                                                                                                                                                                                             ||
|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `executor` | `Executor`: The executor on which the listener should be called back. This value cannot be`null`. Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/Executor), providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use[Context.getMainExecutor()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br /> |
| `listener` | `UiModeManager.ContrastChangeListener`: The listener. This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

### disableCarMode

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void disableCarMode (int flags)
```

Turn off special mode if currently in car mode.

<br />

|                                                                                        Parameters                                                                                        ||
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `flags` | `int`: One of the disable car mode flags. Value is[DISABLE_CAR_MODE_GO_HOME](https://developer.android.com/reference/android/app/UiModeManager#DISABLE_CAR_MODE_GO_HOME) <br /> |

### enableCarMode

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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.

<br />

|            Parameters             ||
|---------|--------------------------|
| `flags` | `int`: Must be 0. <br /> |

### getContrast

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public float getContrast ()
```

Returns the color contrast for the user.

**Note:**You need to query this only if your application is doing its own rendering and does not rely on the material rendering pipeline.

<br />

<br />

|                                                                                                             Returns                                                                                                             ||
|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `float` | The color contrast, float in \[-1, 1\] where - 0 corresponds to the default contrast - -1 corresponds to the minimum contrast - 1 corresponds to the maximum contrast Value is between -1.0f and 1.0f inclusive <br /> |

### getCurrentModeType

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int getCurrentModeType ()
```

Return the current running mode type. May be one of[Configuration.UI_MODE_TYPE_NORMAL](https://developer.android.com/reference/android/content/res/Configuration#UI_MODE_TYPE_NORMAL),[Configuration.UI_MODE_TYPE_DESK](https://developer.android.com/reference/android/content/res/Configuration#UI_MODE_TYPE_DESK),[Configuration.UI_MODE_TYPE_CAR](https://developer.android.com/reference/android/content/res/Configuration#UI_MODE_TYPE_CAR),[Configuration.UI_MODE_TYPE_TELEVISION](https://developer.android.com/reference/android/content/res/Configuration#UI_MODE_TYPE_TELEVISION),[Configuration.UI_MODE_TYPE_APPLIANCE](https://developer.android.com/reference/android/content/res/Configuration#UI_MODE_TYPE_APPLIANCE),[Configuration.UI_MODE_TYPE_WATCH](https://developer.android.com/reference/android/content/res/Configuration#UI_MODE_TYPE_WATCH), or[Configuration.UI_MODE_TYPE_VR_HEADSET](https://developer.android.com/reference/android/content/res/Configuration#UI_MODE_TYPE_VR_HEADSET).

<br />

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### getCustomNightModeEnd

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public LocalTime getCustomNightModeEnd ()
```

Returns the time of the day Dark theme deactivates

When night mode is[MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM), the system uses this time set to deactivate it automatically.

<br />

|                                                   Returns                                                    ||
|--------------------------------------------------------------------------|------------------------------------|
| [LocalTime](https://developer.android.com/reference/java/time/LocalTime) | This value cannot be`null`. <br /> |

### getCustomNightModeStart

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public LocalTime getCustomNightModeStart ()
```

Returns the time of the day Dark theme activates

When night mode is[MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM), the system uses this time set to activate it automatically.

<br />

|                                                   Returns                                                    ||
|--------------------------------------------------------------------------|------------------------------------|
| [LocalTime](https://developer.android.com/reference/java/time/LocalTime) | This value cannot be`null`. <br /> |

### getNightMode

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int getNightMode ()
```

Returns the currently configured night mode.

May be one of:

- [MODE_NIGHT_NO](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_NO)
- [MODE_NIGHT_YES](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_YES)
- [MODE_NIGHT_AUTO](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_AUTO)
- [MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM)
- `-1`on error

<br />

<br />

|                                                                                                                                                                                                                                      Returns                                                                                                                                                                                                                                      ||
|-------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | the current night mode, or`-1`on error Value is[MODE_NIGHT_AUTO](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_AUTO),[MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM),[MODE_NIGHT_NO](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_NO), or[MODE_NIGHT_YES](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_YES) <br /> |

**See also:**

- [setNightMode(int)](https://developer.android.com/reference/android/app/UiModeManager#setNightMode(int))  

### removeContrastChangeListener

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void removeContrastChangeListener (UiModeManager.ContrastChangeListener listener)
```

Unregisters a[ContrastChangeListener](https://developer.android.com/reference/android/app/UiModeManager.ContrastChangeListener)for the user. If the listener was not registered, does nothing and returns.

<br />

|                                                     Parameters                                                     ||
|------------|--------------------------------------------------------------------------------------------------------|
| `listener` | `UiModeManager.ContrastChangeListener`: The listener to unregister. This value cannot be`null`. <br /> |

### setApplicationNightMode

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setApplicationNightMode (int mode)
```

Sets and persist the night mode for this application.

The mode can be one of:

- *[MODE_NIGHT_NO](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_NO)* sets the device into`notnight`mode
- *[MODE_NIGHT_YES](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_YES)* sets the device into`night`mode
- *[MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM)* automatically switches between`night`and`notnight`based on the custom time set (or default)
- *[MODE_NIGHT_AUTO](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_AUTO)* automatically switches between`night`and`notnight`based on the device's current location and certain other sensors

Changes to night mode take effect locally and will result in a configuration change (and potentially an Activity lifecycle event) being applied to this application. The mode is persisted for this application until it is either modified by the application, the user clears the data for the application, or this application is uninstalled.

Developers interested in a non-persistent app-local implementation of night mode should consider using[AppCompatDelegate.setDefaultNightMode(int)](https://developer.android.com/reference/androidx/appcompat/app/AppCompatDelegate.html#setDefaultNightMode(int))to manage the -night qualifier locally.

<br />

|                                                                                                                                                                                                                                Parameters                                                                                                                                                                                                                                ||
|--------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mode` | `int`: the night mode to set Value is[MODE_NIGHT_AUTO](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_AUTO),[MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM),[MODE_NIGHT_NO](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_NO), or[MODE_NIGHT_YES](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_YES) <br /> |

**See also:**

- [setNightMode(int)](https://developer.android.com/reference/android/app/UiModeManager#setNightMode(int))  

### setCustomNightModeEnd

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setCustomNightModeEnd (LocalTime time)
```

Sets the time of the day Dark theme deactivates

When night mode is[MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM), the system uses this time set to deactivate it automatically.

<br />

|                                                Parameters                                                ||
|--------|--------------------------------------------------------------------------------------------------|
| `time` | `LocalTime`: The time of the day Dark theme should deactivate This value cannot be`null`. <br /> |

### setCustomNightModeStart

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setCustomNightModeStart (LocalTime time)
```

Sets the time of the day Dark theme activates

When night mode is[MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM), the system uses this time set to activate it automatically

<br />

|                                               Parameters                                               ||
|--------|------------------------------------------------------------------------------------------------|
| `time` | `LocalTime`: The time of the day Dark theme should activate This value cannot be`null`. <br /> |

### setNightMode

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setNightMode (int mode)
```

Sets the system-wide night mode.

The mode can be one of:

- *[MODE_NIGHT_NO](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_NO)* sets the device into`notnight`mode
- *[MODE_NIGHT_YES](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_YES)* sets the device into`night`mode
- *[MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM)* automatically switches between`night`and`notnight`based on the custom time set (or default)
- *[MODE_NIGHT_AUTO](https://developer.android.com/reference/android/app/UiModeManager#MODE_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](https://developer.android.com/reference/android/content/res/Configuration#UI_MODE_TYPE_CAR)or[desk](https://developer.android.com/reference/android/content/res/Configuration#UI_MODE_TYPE_DESK)mode is enabled on a device. On API 23 through API 28, changes to night mode are always effective.

Starting in API 29, when the device is in car mode and this method is called, night mode will change, but the new setting is not persisted and the previously persisted setting will be restored when the device exits car mode.

Changes to night mode take effect globally and will result in a configuration change (and potentially an Activity lifecycle event) being applied to all running apps. Developers interested in an app-local implementation of night mode should consider using[setApplicationNightMode(int)](https://developer.android.com/reference/android/app/UiModeManager#setApplicationNightMode(int))to set and persist the -night qualifier locally or[AppCompatDelegate.setDefaultNightMode(int)](https://developer.android.com/reference/androidx/appcompat/app/AppCompatDelegate.html#setDefaultNightMode(int))for the backward compatible implementation.

<br />

|                                                                                                                                                                                                                                Parameters                                                                                                                                                                                                                                ||
|--------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mode` | `int`: the night mode to set Value is[MODE_NIGHT_AUTO](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_AUTO),[MODE_NIGHT_CUSTOM](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_CUSTOM),[MODE_NIGHT_NO](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_NO), or[MODE_NIGHT_YES](https://developer.android.com/reference/android/app/UiModeManager#MODE_NIGHT_YES) <br /> |

**See also:**

- [getNightMode()](https://developer.android.com/reference/android/app/UiModeManager#getNightMode())
- [setApplicationNightMode(int)](https://developer.android.com/reference/android/app/UiModeManager#setApplicationNightMode(int))