One thing I found out about is that if your phone has a 100 percent battery level, you wonβt receive a payment notification. Some people mean charging, while others mean when it has external power, regardless of whether it is 100% or not. I focused them on one thing, and if any condition is true, I will return.
public static boolean isPhonePluggedIn(Context context){ boolean charging = false; final Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); boolean batteryCharge = status==BatteryManager.BATTERY_STATUS_CHARGING; int chargePlug = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB; boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC; if (batteryCharge) charging=true; if (usbCharge) charging=true; if (acCharge) charging=true; return charging; }
Jpg
source share