Android examples for Phone:Power
is Phone Connected to Power
//package com.java2s; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; public class Main { public static boolean isConnected(Context context) { Intent intent = context.registerReceiver(null, new IntentFilter( Intent.ACTION_BATTERY_CHANGED)); int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB; }//w ww .j a v a 2 s . co m }