1

Does android provide any native way to know that device is in night mode or not for 3rd party apps?

I am developing app to implement enable/disable night mode within app as per sunset and sunrise respectively.

 UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
    if (isNightMode) {
        uiManager.enableCarMode(0);
        uiManager.setNightMode(UiModeManager.MODE_NIGHT_YES);
    } else {
        uiManager.disableCarMode(0);
        uiManager.setNightMode(UiModeManager.MODE_NIGHT_NO);
    }

UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
    if (nightMode) {
        uiManager.enableCarMode(0);
        uiManager.setNightMode(UiModeManager.MODE_NIGHT_YES);
    } else {
        uiManager.disableCarMode(0);
        uiManager.setNightMode(UiModeManager.MODE_NIGHT_NO);
    }

But this do not answer that how app will get to know that now is the time to show night mode?

Thanks in advance . Any help is much appreciated.

Shivam Oberoi
  • 1,447
  • 1
  • 9
  • 18
SimpleCoder
  • 1,665
  • 1
  • 21
  • 34

0 Answers0