2

I can read the value of the instantaneous current with _CURRENT_NOW and get the remaining battery capacity in percentage with _CAPACITY. The problem is that I can't have access to the remaining battery capacity in mAh with the property _CHARGE_COUNTER (nor _ENERGY_COUNTER). Is it due to an hardware reason or is it not possible on an unrooted phone? I can't figure why the code bellow isn't working.

        TextView current = (TextView) findViewById(R.id.current);
    TextView chargeCounter = (TextView) findViewById(R.id.chargeCounter);
    TextView batteryLevel = (TextView) findViewById(R.id.batteryLevel);
    TextView energyCounter = (TextView) findViewById(R.id.energyCounter);

    BatteryManager batteryManager = (BatteryManager) getSystemService(BATTERY_SERVICE);

    long cu =  batteryManager.getLongProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_NOW);
    long q = batteryManager.getLongProperty(BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER);
    long level = batteryManager.getLongProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
    long energy = batteryManager.getLongProperty(BatteryManager.BATTERY_PROPERTY_ENERGY_COUNTER);

    current.setText("Current : " + String.valueOf(cu) + " mA");
    chargeCounter.setText("Remaining capacity : " + String.valueOf(q) + " uAh");
    batteryLevel.setText("Battery status : " + String.valueOf(level) + " %");
    energyCounter.setText("Battery status : " + String.valueOf(energy) + " %");

For each property that doesn't work I have this enormous number : 9223372036854775808

For more information : https://source.android.com/devices/tech/power/device

Thanks!

Taku
  • 31,927
  • 11
  • 74
  • 85
Ilan
  • 729
  • 3
  • 8
  • 17

1 Answers1

2

the value is Long.MIN_VALUE, because your phone not support it,you can see it at https://developer.android.google.cn/reference/android/os/BatteryManager.html

chen
  • 172
  • 1
  • 7