I'm trying to make a settings option that allows the user to choose whether the app should be in night mode, day mode or follow the system default. In order to display the current setting to the user I need to get it from the system. However the code I'm using below always returns MODE_NIGHT_UNSPECIFIED
. Am I doing something wrong here?
I have the following code:
val x = AppCompatDelegate.getDefaultNightMode()
when (x) {
AppCompatDelegate.MODE_NIGHT_NO -> {"testsadflke- MODE_NIGHT_NO".log()}
AppCompatDelegate.MODE_NIGHT_YES -> {"testsadflke- MODE_NIGHT_YES".log()}
AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY -> {"testsadflke- MODE_NIGHT_AUTO_BATTERY".log()}
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> {"testsadflke- MODE_NIGHT_FOLLOW_SYSTEM".log()}
AppCompatDelegate.MODE_NIGHT_UNSPECIFIED -> {"testsadflke- MODE_NIGHT_UNSPECIFIED".log()}
}
The log output is:
2020-07-01 21:47:08.751 6783-6783/com.example.macrotracker D/(AnyExt.kt:6)log(): Object: testsadflke- MODE_NIGHT_UNSPECIFIED
However I think this is incorrect because my appTheme extends the material DayNight theme. Additionally, when I enable or disable night mode, my app changes theme, so it must be following the system mode. Any help would be much appreciated!