'How do I check whether night mode was turned on or off

I don't want to know what is the current going on mode (dark or light) in my android device. I want to know if the mode was switched at the time my android activity was running. How do I put a check for it? Is there any in-built method for it? If not, then how to do it? I am using Java and I am a beginner.



Solution 1:[1]

int currentNightMode = configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
    case Configuration.UI_MODE_NIGHT_NO:
        // Night mode is not active, we're using the light theme
        break;
    case Configuration.UI_MODE_NIGHT_YES:
        // Night mode is active, we're using dark theme
        break;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 IX0Y3