desc:充电逻辑完善

main
xiaowusky 1 year ago
parent 6094140fa6
commit 4f42e76383

@ -25,25 +25,33 @@ object BatteryHelper {
val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)!! val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)!!
val status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); val status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
val isCharging = val isCharging =
(status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL) (status == BatteryManager.BATTERY_STATUS_CHARGING)
notifyUser(level) notifyUser(level)
mLevel = level mLevel = level
Log.i( Log.i(
this@BatteryHelper.javaClass.name, this@BatteryHelper.javaClass.name,
"onReceive level = $level isCharging = $isCharging" "onReceive level = $level, status = $status, isCharging = $isCharging"
) )
callbacks.forEach { 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 { callbacks.forEach {
it.onLevel(mLevel, batteryManager?.isCharging == true) it.onLevel(mLevel, true)
} }
} else if (Intent.ACTION_POWER_DISCONNECTED == action) { } else if (Intent.ACTION_POWER_DISCONNECTED == action) {
Log.i(
this@BatteryHelper.javaClass.name,
"onReceive ACTION_POWER_DISCONNECTED"
)
callbacks.forEach { callbacks.forEach {
it.onLevel(mLevel, batteryManager?.isCharging == true) it.onLevel(mLevel, false)
} }
} }*/
} }
} }
@ -83,8 +91,8 @@ object BatteryHelper {
private fun watchBattery(context: Context) { private fun watchBattery(context: Context) {
val filter = IntentFilter(Intent.ACTION_BATTERY_CHANGED) val filter = IntentFilter(Intent.ACTION_BATTERY_CHANGED)
filter.addAction(Intent.ACTION_POWER_CONNECTED) // filter.addAction(Intent.ACTION_POWER_CONNECTED)
filter.addAction(Intent.ACTION_POWER_DISCONNECTED) // filter.addAction(Intent.ACTION_POWER_DISCONNECTED)
context.registerReceiver(receiver, filter) context.registerReceiver(receiver, filter)
} }

Loading…
Cancel
Save