Skip to content Skip to sidebar Skip to footer

Android Usb Connection Charging Signals

How can I check the USB socket is plugged or not (Charging with AC / USB)? (android version 2.1 / 2.2) I am writing a wireless charging application that I want to get different typ

Solution 1:

To check device charging with AC / USB, Lets try this,

Call registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)). This will return an Intent that has extras defined on BatteryManager to let you know if it is plugged in or not.

Something with code,

publicclassPowerUtil {
    publicstaticbooleanisConnected(Context context) {
        Intentintent= context.registerReceiver(null, newIntentFilter(Intent.ACTION_BATTERY_CHANGED));
        intplugged= intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
        returnplugged== BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB;
    }
}

Solution 2:

As of Jellybean 4.2 there is BatterManager.BATTERY_PLUGGED_WIRELESS

Post a Comment for "Android Usb Connection Charging Signals"