Android的BatteryManager所有财产检索调用返回0 [英] Android BatteryManager returning 0 for all property-retrieval calls
问题描述
我在遇到麻烦尝试访问大部分来自Android设备的电池的统计数据,如 BATTERY_PROPERTY_CAPACITY
, BATTERY_PROPERTY_CHARGE_COUNTER
或 BATTERY_PROPERTY_CURRENT_AVERAGE
。这些属性都清楚地记录在这里: http://developer.android.com/reference /android/os/BatteryManager.html
I'm having trouble trying to access most of the stats from my Android device's battery such as BATTERY_PROPERTY_CAPACITY
, BATTERY_PROPERTY_CHARGE_COUNTER
or BATTERY_PROPERTY_CURRENT_AVERAGE
. These properties are all clearly documented here: http://developer.android.com/reference/android/os/BatteryManager.html
我有我的清单中声明如下权限:
I have the following permission declared on my manifest:
<uses-permission android:name="android.permission.BATTERY_STATS" />
我有一个非空BatteryManager例如:
I have a non-null BatteryManager instance:
mBatteryManager = (BatteryManager) getSystemService(BATTERY_SERVICE);
和每当我试图找回这些统计数据:
And whenever I try to retrieve these stats:
double remainingCapacity = mBatteryManager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY);
double batteryCapacityMicroAh = mBatteryManager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER);
double averageCurrentMicroA = mBatteryManager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CURRENT_AVERAGE);
结果都是0所有这些的。总是,没有失败,0。我已经试过这个模拟器上,实际的设备,我已经想到了一切都无法修改我的结果。
The results are all 0 for all of those. Always, without fail, 0. I've tried this on an emulator, an actual device, and everything I've thought of has failed to modify my results.
我会非常AP preciate任何帮助。最后,我想要做的就是计算出剩余达到其完全充电(充电时)的设备的时间。先谢谢了。
I'd greatly appreciate any help. Ultimately, what I'm trying to do is calculate the time remaining for a device to reach its full charge (while charging). Thanks in advance.
推荐答案
不知道这是给你的任何帮助了,但只有具有电池电量计(的 https://source.android.com/devices/tech/power/device.html )能够回报一些值您正在寻找。据我所知,只有Nexus的6,9,和10给你正在寻找所有三个值,使用Nexus 5只给 BATTERY_PROPERTY_CAPACITY
。
Not sure if this is any help for you now, but only phones that have a battery fuel gauge (https://source.android.com/devices/tech/power/device.html) can report back some of the values you are looking for. AFAIK, only the Nexus 6, 9, and 10 gives all three values you are looking for, with Nexus 5 giving only BATTERY_PROPERTY_CAPACITY
.
这篇关于Android的BatteryManager所有财产检索调用返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!