diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/ChargingStateReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/ChargingStateReceiver.kt index 321eaf1b6c..5923978509 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/ChargingStateReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/ChargingStateReceiver.kt @@ -32,12 +32,15 @@ class ChargingStateReceiver : DaggerBroadcastReceiver() { var batteryLevel = 0 val level = batteryStatus?.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) ?: -1 val scale = batteryStatus?.getIntExtra(BatteryManager.EXTRA_SCALE, -1) ?: -1 + val plugged = batteryStatus?.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) ?: -1 if (level != -1 && scale != -1) batteryLevel = (level.toFloat() / scale.toFloat() * 100.0f).toInt() - // Status - val status: Int = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1) ?: -1 - val isCharging: Boolean = status == BatteryManager.BATTERY_STATUS_CHARGING - || status == BatteryManager.BATTERY_STATUS_FULL + // Plugged + val isCharging: Boolean = + plugged == BatteryManager.BATTERY_PLUGGED_AC || + plugged == BatteryManager.BATTERY_PLUGGED_USB || + plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS || + plugged == BatteryManager.BATTERY_PLUGGED_DOCK return EventChargingState(isCharging, batteryLevel).also { receiverStatusStore.lastChargingEvent = it } }