Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Android L Battery Saver

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?

like image 916
mobiledevbrick Avatar asked Jul 29 '14 14:07

mobiledevbrick


1 Answers

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.

like image 58
Joseph Earl Avatar answered Oct 13 '22 00:10

Joseph Earl