Android examples for android.os:Battery
is Battery Charging for JellyBean and older version
import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; import android.os.Build; public class Main{ public static boolean isCharging(Context context) { IntentFilter filter = new IntentFilter( Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = context.registerReceiver(null, filter); int chargePlug = batteryStatus.getIntExtra( BatteryManager.EXTRA_PLUGGED, -1); boolean usbCharge = (chargePlug == BatteryManager.BATTERY_PLUGGED_USB); boolean acCharge = (chargePlug == BatteryManager.BATTERY_PLUGGED_AC); boolean wirelessCharge = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { wirelessCharge = (chargePlug == BatteryManager.BATTERY_PLUGGED_WIRELESS); }/*from w ww .ja v a 2 s. co m*/ return (usbCharge || acCharge || wirelessCharge); } }