gpt4 book ai didi

android - 解码电池值

转载 作者:行者123 更新时间:2023-11-29 16:05:05 25 4
gpt4 key购买 nike

在电池的广播接收器中,我有以下 3 行代码:

int health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
int voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0);

以上三个的值分别为 2,2 和 4。

我如何解码这些值并向用户展示一些对健康有意义的东西,如果电池健康状况好、坏或需要更换,我不能告诉计算机如何。

提前致谢

最佳答案

用这个做电池

switch (health) {
case BatteryManager.BATTERY_HEALTH_DEAD:

break;
case BatteryManager.BATTERY_HEALTH_GOOD:

break;
case BatteryManager.BATTERY_HEALTH_COLD:

break;
case BatteryManager.BATTERY_HEALTH_OVERHEAT:

break;
case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:

break;

default:
break;
}

用于插入

switch (plugged ) {
case BatteryManager.BATTERY_PLUGGED_AC:

break;
case BatteryManager.BATTERY_PLUGGED_USB:

break;
case BatteryManager.BATTERY_PLUGGED_WIRELESS:

default:
break;
}

用于电压

switch (voltage) {
case BatteryManager.BATTERY_STATUS_CHARGING:

break;
case BatteryManager.BATTERY_STATUS_DISCHARGING:

break;
case BatteryManager.BATTERY_STATUS_FULL:
break;
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
break;
case BatteryManager.BATTERY_STATUS_UNKNOWN:
break;
default:
break;
}

关于android - 解码电池值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19628316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com