1. 程式人生 > >Android BatteryManager類

Android BatteryManager類

相關文章
Android BatteryManager類
Android TelephonyManager類
Android ConnectivityManager類
Android Vibrator類

1. BatteryManager類

獲取電量資訊需要註冊一個BroadcastReceiver

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

onReceive(Context context, Intent intent)

方法中,通過intent.getXXXExtra()獲取電量資訊。

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,電池技術