fix NPE
This commit is contained in:
parent
d925011380
commit
7f17110d98
1 changed files with 3 additions and 0 deletions
|
@ -21,6 +21,9 @@ public class ChargingStateReceiver extends BroadcastReceiver {
|
||||||
public EventChargingState grabChargingState(Context context) {
|
public EventChargingState grabChargingState(Context context) {
|
||||||
BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
|
BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
|
||||||
|
|
||||||
|
if (bm == null)
|
||||||
|
return new EventChargingState(false);
|
||||||
|
|
||||||
int status = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_STATUS);
|
int status = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_STATUS);
|
||||||
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING
|
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING
|
||||||
|| status == BatteryManager.BATTERY_STATUS_FULL;
|
|| status == BatteryManager.BATTERY_STATUS_FULL;
|
||||||
|
|
Loading…
Add table
Reference in a new issue