0

When I try to change theme of system using Android UiModeManager on Android 10 nothings changing while it's working on Android versions less than 10. `

UiModemanger uiMode = (UiModemanger) getSystemService(Context.UI_MODE_SERVICE);
uiMode.setNightMode(UiModeManager.NIGHT_MODE_YES);

Its working on all Android versions except 10.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Noyal Jose
  • 11
  • 2

1 Answers1

-1

According to Android docs:

Note: On API 22 and below, changes to the night mode are only effective when the Configuration#UI_MODE_TYPE_CAR or 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 AppCompatDelegate.setDefaultNightMode(int) to manage the -night qualifier locally.

This method only works in Android 10 if car mode is enabled.

greywolf82
  • 21,813
  • 18
  • 54
  • 108
  • So should I also enable car mode in Android 10 for the night mode to work? – Noyal Jose Dec 08 '19 at 13:29
  • so is there any way to enable car mode without showing the notification – Noyal Jose Dec 21 '19 at 07:51
  • On Android 10 if device in car mode then setNightMode has same effect as not in car mode. The only difference between 23-28 and 29 is after exit car mode may be restored on api 29 – Romadro Apr 15 '20 at 16:38