Detecting Android L Battery Saver

拈花ヽ惹草 提交于 2019-12-20 19:56:30

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/25018132/detecting-android-l-battery-saver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!