Android的电池在SDK电池、Android、SDK

2023-09-11 12:34:43 作者:5.孤绝如初见

有没有办法从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.

 
精彩推荐
图片推荐