Android BatteryManager returns 0 for all property search calls

I'm having trouble trying to access most of the data from my battery of Android devices, such as BATTERY_PROPERTY_CAPACITY, BATTERY_PROPERTY_CHARGE_COUNTERor BATTERY_PROPERTY_CURRENT_AVERAGE. These properties are clearly described here: http://developer.android.com/reference/android/os/BatteryManager.html

I have the following permission declared in my manifest:

<uses-permission android:name="android.permission.BATTERY_STATS" />

I have a non-zero instance of BatteryManager:

mBatteryManager = (BatteryManager) getSystemService(BATTERY_SERVICE);

And whenever I try to get this data:

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);

All results are equal to 0. Always, without fail, 0. I tried it on the emulator, in fact, and everything that I thought about, could not change my results.

. , , , , , ( ). .

+4
3

, , (https://source.android.com/devices/tech/power/device.html) , . AFAIK, Nexus 6, 9 10 , , Nexus 5 BATTERY_PROPERTY_CAPACITY.

+3

Action_Battery_Changed. . , . .

private void getBatteryPercentage() {
    BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            context.unregisterReceiver(this);
            int currentLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
            int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
            int level = -1;
            if (currentLevel >= 0 && scale > 0) {
                level = (currentLevel * 100) / scale;
            }
            Toast.makeText(MainActivity.this, level + "%", Toast.LENGTH_LONG).show();
        }
    };
    IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    registerReceiver(batteryLevelReceiver, batteryLevelFilter);
}
0

BatteryManager.EXTRA_LEVEL - . , (), /sys/class/power _supply/battery/charge_full_design charge_full, .

0

All Articles