在ACTION_POWER_CONNECTED电池状态 [英] battery status on ACTION_POWER_CONNECTED

查看:1488
本文介绍了在ACTION_POWER_CONNECTED电池状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道是否有任何可能获得在对ACTION_POWER_CONNECTED触发广播接收机类电池状态?文件建议不要,但它始终是值得问:)

I'm just wondering if is there any possibility to obtain battery status in broadcast receiver class that fires on ACTION_POWER_CONNECTED? Documentation suggest not, but it is always worth to ask :)

干杯

推荐答案

呼叫 registerReceiver(空,新的IntentFilter(Intent.ACTION_BATTERY_CHANGED))。在意图则返回的最后一次广播 ACTION_BATTERY_CHANGED 播出,这在其额外的电池状态(见 BatteryManager 的键)。

Call registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)). The Intent that is returned is the last-broadcast ACTION_BATTERY_CHANGED broadcast, which has your battery status in its extras (see BatteryManager for the keys).

如果您确定您太快调用它, ACTION_POWER_CONNECTED 之前 ACTION_BATTERY_CHANGED 调用得到,也许更新使用 AlarmManager 来安排自己在几秒钟醒一次,然后再次进行检查。

If you determine that you are calling it too soon, that ACTION_POWER_CONNECTED is invoked before ACTION_BATTERY_CHANGED gets updated, perhaps use AlarmManager to schedule yourself to wake up again in a few seconds, and check again then.

这篇关于在ACTION_POWER_CONNECTED电池状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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