我如何检查是否在Android手机正在充电 [英] How can I check if the android phone is charging
问题描述
我写一个Android应用程序。我想知道我怎么能检查是否是手机在充电时,我的应用程序启动?
I am writing an android application. I would like to know how can I check if the phone is charging when my application starts?
我已阅读本如何知道手机正在充电
但这只注册并得到通知时,没有在手机充电时的状态(从充电到停止充电或反之亦然)的变化。但是,如果是手机在充电时,我的应用程序启动时,我怎么能掩盖这种情况下?
But this only register and get notified when there is a change in charging state of the phone (from charging to stop charging or vice versa). But what if the phone is charging when my application starts, how can I cover that case?
我已经看过了电源管理器和USBManager的机器人。无论是拥有API,它提供了我所需要的。
I have looked up PowerManager and USBManager in android. Neither has API which provides what I need.
感谢你。
推荐答案
这个问题提供了c您的$ C $可能会寻找:<一href="http://stackoverflow.com/questions/2104372/android-event-action-power-connected-is-not-sent-to-my-broadcastreceiver">Event ACTION_POWER_CONNECTED不会被发送到我的BroadcastReceiver
This question provides the code you might be looking for: Event ACTION_POWER_CONNECTED is not sent to my BroadcastReceiver
还有一个ACTION_POWER_DISCONNECTED行动。
There's also a ACTION_POWER_DISCONNECTED action.
这个问题清楚了,广播是粘性的,所以即使可当你错过了广播:的 Android的电池在SDK
This question is telling that the broadcast is sticky, so even available when you miss the broadcast: Android Battery in SDK
这篇关于我如何检查是否在Android手机正在充电的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!