One of the new features of Android L is a battery saver that kicks in at 15%. Is there some way to detect when this is active, so my app will respond correctly?
http://www.technobuffalo.com/2014/07/02/android-l-project-volta-battery-life/
I would like my app to get a callback from the operating system when the this mode is active so I can stop background services. If there is no callback, I could make a background process query for the battery level, but that seems wasteful. I also do not want to hard-code a 15% level into the app, because I assume this level will be configurable.
Is there a way to get a callback in Java code?
android.os.PowerManager
has a new method, boolean isPowerSaveMode()
. You can download the preview SDK docs at http://developer.android.com/preview/reference.html to see the new APIs.
There's also a broadcast intent ACTION_POWER_SAVE_MODE_CHANGED
when this changes.
You might also want to look into the JobScheduler
API as this allows you to easily run tasks and only have them execute when there is a sufficient power or a network connection for instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With