I am trying to create an app that toggles the Dark Mode (Night mode) for the whole system. Not just for my app. I am creating and automation app, so the user decides what to enable or what to disable in just on touch.
To activate the Night mode I do this:
UiModeManager oUiModeManager = (UiModeManager) getApplicationContext().getSystemService(Context.UI_MODE_SERVICE);
oUiModeManager.setNightMode(UiModeManager.MODE_NIGHT_YES);
and to deactivate I do this:
UiModeManager oUiModeManager = (UiModeManager) getApplicationContext().getSystemService(Context.UI_MODE_SERVICE);
oUiModeManager.setNightMode(UiModeManager.MODE_NIGHT_NO);
But nothing happens. The dark mode doesn't get activated or deactivated. I have tried with Android 10-Q, Android 11-R and Android 12-S devices. So, how am I supposed to solve this? Remember I need to toggle the whole system dark mode, not just for my app. Thanks
Issue tracker here: https://issuetracker.google.com/issues/173628055 But not answers from Google Developers.