Android BatteryManager类

1. BatteryManager类

获取电量信息需要注册一个BroadcastReceiver

IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(mReceiver, filter);

onReceive(Context context, Intent intent)方法中,通过intent.getExtra()获取电量信息。

2. 主要参数

  • BatteryManager.EXTRA_STATUS,电池状态

    BatteryManager.BATTERY_STATUS_UNKNOWN
    BatteryManager.BATTERY_STATUS_CHARGING
    BatteryManager.BATTERY_STATUS_DISCHARGING
    BatteryManager.BATTERY_STATUS_NOT_CHARGING
    BatteryManager.BATTERY_STATUS_FULL
    
  • BatteryManager.EXTRA_HEALTH,电池健康状态

    BatteryManager.BATTERY_HEALTH_UNKNOWN
    BatteryManager.BATTERY_HEALTH_GOOD
    BatteryManager.BATTERY_HEALTH_OVERHEAT
    BatteryManager.BATTERY_HEALTH_DEAD
    BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE
    BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE
    BatteryManager.BATTERY_HEALTH_COLD
    
  • BatteryManager.EXTRA_PRESENT,电池是否存在

  • BatteryManager.EXTRA_LEVEL,电池电量

  • BatteryManager.EXTRA_SCALE,电池总电量

  • BatteryManager.EXTRA_PLUGGED,充电方式

    BatteryManager.BATTERY_PLUGGED_AC
    BatteryManager.BATTERY_PLUGGED_USB
    BatteryManager.BATTERY_PLUGGED_WIRELESS
    
  • BatteryManager.EXTRA_VOLTAGE,电池电压

  • BatteryManager.EXTRA_TEMPERATURE,电池温度

  • BatteryManager.EXTRA_TECHNOLOGY,电池技术

你可能感兴趣的:(Android,特性)