本文介绍了Android的电池在SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法从Android SDK中获取电池信息?比如电池的剩余电量等?我找不到它通过文档。
Is there a way to get battery information from the Android SDK? Such as battery life remaining and so on? I cannot find it through the docs.
推荐答案
您可以注册一个Intent接收器来接收广播的ACTION_BATTERY_CHANGED:http://developer.android.com/reference/android/content/Intent.html#ACTION_BATTERY_CHANGED.该文档说,广播是粘性的,所以你可以即使在电池状态发生变化的时刻抓住它。
You can register an Intent receiver to receive the broadcast for ACTION_BATTERY_CHANGED: http://developer.android.com/reference/android/content/Intent.html#ACTION_BATTERY_CHANGED. The docs say that the broadcast is sticky, so you'll be able to grab it even after the moment the battery state change occurs.
这篇关于Android的电池在SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!