File tree Expand file tree Collapse file tree
mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5151public class MapboxTelemetry implements Callback , LocationEngineListener {
5252
5353 private static final String LOG_TAG = MapboxTelemetry .class .getSimpleName ();
54+ private static final int UNAVAILABLE_BATTERY_LEVEL = 100 ;
5455
5556 private static MapboxTelemetry instance ;
5657
@@ -241,9 +242,13 @@ private void registerBatteryUpdates() {
241242 }
242243
243244 private int getBatteryLevel () {
244- int level = batteryStatus .getIntExtra (BatteryManager .EXTRA_LEVEL , -1 );
245- int scale = batteryStatus .getIntExtra (BatteryManager .EXTRA_SCALE , -1 );
246- return Math .round ((level / (float ) scale ) * 100 );
245+ if (batteryStatus != null ) {
246+ int level = batteryStatus .getIntExtra (BatteryManager .EXTRA_LEVEL , -1 );
247+ int scale = batteryStatus .getIntExtra (BatteryManager .EXTRA_SCALE , -1 );
248+ return Math .round ((level / (float ) scale ) * 100 );
249+ } else {
250+ return UNAVAILABLE_BATTERY_LEVEL ;
251+ }
247252 }
248253
249254 /**
You can’t perform that action at this time.
0 commit comments