2011년 5월 19일 목요일

Android - about Battery BroadcastReceiver...

public void onReceive(Context arg0, Intent intent){
  int level = intent.getIntExtra("level", 0);
  int scale = int.getIntExtra("scale", 100);

  System.out.println(String.valueOf((level / scale) * 100) + "%");


  int plugType = intent.getIntExtra("plugged", 0);

  /*
  plugType is
     BatteryManager.BATTERY_PLUGGED_AC
     or  BatteryManager.BATTERY_PLUGGED_USB
  */

  int status = intent.getIntExtra("status", BatteryManager.BATTERY_STATUS_UNKNOWN);

  /*
  status is
     BatteryManager.BATTERY_STATUS_CHARGING
     or BatteryManager.BATTERY_STATUS_DISCHARGING
     or BatteryManager.BATTERY_STATUS_FULL
     or BatteryManager.BATTERY_STATUS_NOT_CHARGING
     or BatteryManager.BATTERY_STATUS_UNKNOWN
  */

  int temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
/*
temp / 10 = degrees celsius
*/
}