Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; public class Main { private static Boolean isCharging(Context context) { IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = context.registerReceiver(null, ifilter); int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL; } }