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" />
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);
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.
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.
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
.You need to register for Action_Battery_Changed broadcast . This will get invoked whenever this event occurs. Since this is a sticky Intent, it keeps on broadcasting once registered. The method below would get the current level of battery.
Value of BatteryManager.EXTRA_LEVEL is current battery capacity. I guess you are looking for the total capacity(full), you need to read /sys/class/power_supply/battery/charge_full_design or charge_full, different manufacturers may have different path.