From 6094140fa69c18b3643176f67a5c73b40e35a658 Mon Sep 17 00:00:00 2001 From: xiaowusky Date: Thu, 28 Dec 2023 10:23:48 +0800 Subject: [PATCH] =?UTF-8?q?desc:=E5=85=85=E7=94=B5=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../safetywatcher/watcher/utils/BatteryHelper.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/BatteryHelper.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/BatteryHelper.kt index a1fbc3e..fa9c53f 100644 --- a/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/BatteryHelper.kt +++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/BatteryHelper.kt @@ -35,11 +35,15 @@ object BatteryHelper { callbacks.forEach { it.onLevel(level, batteryManager?.isCharging == true) } - } /*else if (Intent.ACTION_POWER_CONNECTED == action) { - charging = true + } else if (Intent.ACTION_POWER_CONNECTED == action) { + callbacks.forEach { + it.onLevel(mLevel, batteryManager?.isCharging == true) + } } else if (Intent.ACTION_POWER_DISCONNECTED == action) { - charging = false - }*/ + callbacks.forEach { + it.onLevel(mLevel, batteryManager?.isCharging == true) + } + } } } @@ -79,8 +83,8 @@ object BatteryHelper { private fun watchBattery(context: Context) { val filter = IntentFilter(Intent.ACTION_BATTERY_CHANGED) -// filter.addAction(Intent.ACTION_POWER_CONNECTED) -// filter.addAction(Intent.ACTION_POWER_DISCONNECTED) + filter.addAction(Intent.ACTION_POWER_CONNECTED) + filter.addAction(Intent.ACTION_POWER_DISCONNECTED) context.registerReceiver(receiver, filter) }