为什么BATTERY_PROPERTY_CHARGE_COUNTER不能用作BATTERY_PROPERTY_CURRENT_NOW?

时间:2017-09-24 15:59:10

标签: android batterymanager

我可以使用_CURRENT_NOW读取瞬时电流的值,并使用_CAPACITY获得剩余电池容量的百分比。问题是我无法使用属性mAh _CHARGE_COUNTER_ENERGY_COUNTER)访问 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

对于不起作用的每个属性,我都有这么多的数字:DECLARE @ColNames NVARCHAR(MAX) ='' SELECT @ColNames = @ColNames + '['+ColumnName +']'+ ', 'FROM tblColumnNames ORDER BY id SET @ColNames = LEFT(@ColNames, LEN(@ColNames)-1) DECLARE @TheQuery NVARCHAR(MAX) SET @TheQuery = 'SELECT PVT.* FROM (SELECT V.Value, (V.id - V.ColumnId) RowGroupID, C.ColumnName FROM tblValues V INNER JOIN tblColumnNames C ON V.ColumnId = C.id ) AS SRC PIVOT ( MAX(VALUE) FOR ColumnName IN ('+ @ColNames +')) PVT' EXEC sp_executesql @TheQuery

有关详细信息:https://source.android.com/devices/tech/power/device

谢谢!

1 个答案:

答案 0 :(得分:2)

值为Long.MIN_VALUE,因为您的手机不支持,您可以在https://developer.android.google.cn/reference/android/os/BatteryManager.html

看到它