我可以使用_CURRENT_NOW读取瞬时电流的值,并使用_CAPACITY以百分比形式获得剩余电池容量。问题是,我无法使用属性_CHARGE_COUNTER (也不是_ENERGY_COUNTER)访问mAh中的剩余电池容量。这是由于硬件原因,还是在未扎根的手机上不可能?我不明白为什么下面的代码不能工作。
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) + " %");对于每个不起作用的属性,我都有一个巨大的数字:9223372036854775808
欲了解更多信息,请访问:https://source.android.com/devices/tech/power/device
谢谢!
发布于 2017-10-25 17:05:08
这个值是Long.MIN_VALUE,因为你的手机不支持它,你可以在https://developer.android.google.cn/reference/android/os/BatteryManager.html上看到它
https://stackoverflow.com/questions/46391998
复制相似问题