BatteryManager Health values

喜夏-厌秋 提交于 2019-12-11 01:55:57

问题


I was wondering about the value that I get from the BatteryManager when I want to have the health. I get a "2". What does it mean? Can anyone give me all the values I can get and their meanings?

Here is my code for what I want:

int health = batteryIntent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);


回答1:


Take a look at the documentation on Battery Manager.

You'll be able to see what these constant values mean. For example, the value 2 that you get corresponds to BATTERY_HEALTH_GOOD. You can check that here: Link.

In your activity, you can check your integer variable health against these values like:

if (health == BatteryManager.BATTERY_HEALTH_GOOD) {
    // do something, update a textview, show a Toast
} else if (health == BatteryManager.BATTERY_HEALTH_OVERHEAT) {
    // do something else, show a warning
} else if. . . . // check for however many values or check for all

This way, you won't need to consider the actual value(numerical value) that health variable holds.



来源:https://stackoverflow.com/questions/17762243/batterymanager-health-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!