This commit is contained in:
Milos Kozak 2018-08-13 23:57:16 +02:00
parent d925011380
commit 7f17110d98

View file

@ -21,6 +21,9 @@ public class ChargingStateReceiver extends BroadcastReceiver {
public EventChargingState grabChargingState(Context context) {
BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
if (bm == null)
return new EventChargingState(false);
int status = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_STATUS);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING
|| status == BatteryManager.BATTERY_STATUS_FULL;