Search code examples
javaandroidevent-handlinglockscreenandroid-7.0-nougat

Android - keep service responsive from lockscreen


So I have a counter app that uses a VolumeProviderCompat to make a service listen to volume up / down keys. Vol Up = increment, vol down = decrement. This should also be doable from lockscreen - which it is, but only if the device hasn't been locked for too long.

If the device has been locked for a moment (~minutes), the app will not react to key inputs unless the power button is pressed beforehand.

How do I keep the service responsive? (Always-on display is enabled, power saver is off.)


Solution

  • The thing that works for me also with Android 6 Doze mode is on Service start command to call startForeground with a Notification and also acquire a partial Wake Lock. But your app will drain a little the battery