From 4f42e76383dad3cd5cc273e4b7980eeac840aefa Mon Sep 17 00:00:00 2001 From: xiaowusky Date: Thu, 28 Dec 2023 11:04:49 +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 --- .../watcher/utils/BatteryHelper.kt | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 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 fa9c53f..bd2ae66 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 @@ -25,25 +25,33 @@ object BatteryHelper { val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)!! val status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); val isCharging = - (status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL) + (status == BatteryManager.BATTERY_STATUS_CHARGING) notifyUser(level) mLevel = level Log.i( this@BatteryHelper.javaClass.name, - "onReceive level = $level isCharging = $isCharging" + "onReceive level = $level, status = $status, isCharging = $isCharging" ) callbacks.forEach { - it.onLevel(level, batteryManager?.isCharging == true) + it.onLevel(level, isCharging) } - } else if (Intent.ACTION_POWER_CONNECTED == action) { + } /*else if (Intent.ACTION_POWER_CONNECTED == action) { + Log.i( + this@BatteryHelper.javaClass.name, + "onReceive ACTION_POWER_CONNECTED" + ) callbacks.forEach { - it.onLevel(mLevel, batteryManager?.isCharging == true) + it.onLevel(mLevel, true) } } else if (Intent.ACTION_POWER_DISCONNECTED == action) { + Log.i( + this@BatteryHelper.javaClass.name, + "onReceive ACTION_POWER_DISCONNECTED" + ) callbacks.forEach { - it.onLevel(mLevel, batteryManager?.isCharging == true) + it.onLevel(mLevel, false) } - } + }*/ } } @@ -83,8 +91,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) }