检测的Andr​​oid L电池节电器 [英] Detecting Android L Battery Saver

查看:261
本文介绍了检测的Andr​​oid L电池节电器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个Android的L的新功能是,在15%的踢的电池保护程序。是否有某种方式来检测时,这是积极的,所以我的应用程序将正确应对?

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?

<一个href=\"http://www.technobuffalo.com/2014/07/02/android-l-project-volta-battery-life/\">http://www.technobuffalo.com/2014/07/02/android-l-project-volta-battery-life/

我想我的应用程序从操作系统得到一个回调时,此模式被激活,所以我可以停止后台服务。如果没有回调,我可以使对于电池级的后台进程查询,但似乎浪费。我也不想硬code有15%的水平到应用程序,因为我认为这个水平,将是可配置的。

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.

有没有一种方法可以在Java中code回调?

Is there a way to get a callback in Java code?

推荐答案

android.os.PowerManager 有一个新的方法,布尔isPowerSaveMode() 。您可以在<一个下载preVIEW SDK文档href=\"http://developer.android.com/$p$pview/reference.html\">http://developer.android.com/$p$pview/reference.html看到新的API。

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.

还有一个广播意图 ACTION_POWER_SAVE_MODE_CHANGED 时,这改变。

There's also a broadcast intent ACTION_POWER_SAVE_MODE_CHANGED when this changes.

您可能还需要寻找到了的jobscheduler API,因为这可以让你轻松地运行任务,只有当有足够的功率或进行网络连接他们执行实例。

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.

这篇关于检测的Andr​​oid L电池节电器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆