2

I'm working on an Android app that does not need location services, and I don't want to add that permission.

While I'm testing on my physical device (Moto G5 Plus with Android 8.1.0), I see in Logcat the following repeated ad nauseam:

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

I don't want it, I don't need it. I can't figure out how to get rid of it.

android.support.v7.app.TwilightManager.isNight() is apparently getting called by something, but I'm not sure how to tell it not to keep calling it.

I tried several get system service kinds of things, but never found the secret handshake. Besides, TwilightManager is private.

getBlahBlahService(android.support.v7.app.TwilightManager.class);  
//'android.support.v7.app.TwilightManager' is not public in 'android.support.v7.app'. Cannot be accessed from outside package    
Dale
  • 5,520
  • 4
  • 43
  • 79
  • 1
    Call `getDelegate()` on your `AppCompatActivity`, then play around with methods like `setDefaultNightMode()`. If you use something other than `MODE_NIGHT_AUTO`, I think you might avoid those logs. – CommonsWare Mar 22 '19 at 00:01

1 Answers1

1

One way to stop the logging is to tell TwilightManager not to use night mode:

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)

This can be run from your first activity.

Alternatively, you could see why TwilightManager thinks it needs to do anything for you in the first place. Check your styles.xml. Do you have any daynight themes?

<style name="CommonTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">

You might consider alternatives.

Dale
  • 5,520
  • 4
  • 43
  • 79