Android the dark theme does not activate with MODE_NIGHT_AUTO

1

I'm implementing to change the theme of the app depending on whether it's day or night, with NightMode of Android

I have defined the two themes, day and night, that work correctly

To activate the dark / night AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);

To activate the clearing / day AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

But when specifying to activate the light or dark depending on the time of the system, with the value MODE_NIGHT_AUTO never activates at night.

In the log I receive

  

Could not get last known location. This is probably because of the app   does not have any location permissions. Falling back to hardcoded   sunrise / sunset values

    
asked by Webserveis 25.10.2018 в 21:43
source

1 answer

0

I searched for the error and sent me to SO

I guess that to get what time the sun goes down, you must use the last known position for the system, you must grant the permissions for the daynight theme to work

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    
answered by 25.10.2018 / 21:43
source