Android Day/Night Mode. UiModeManafer.getNightMode

751 Views Asked by At

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.

0

There are 0 best solutions below