Androidでバッテリー用量を取得

Javaコード:
private BroadcastReceiver batteryReceiver=new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
int level = intent.getIntExtra(“level", 0);
}
};

activityのonCreate()メソッドに次の内容を追加
registerReceiver(batteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

Android

Posted by arkgame