Commit ecb1cfcd authored by wanglei's avatar wanglei

...

parent 85a1d00d
......@@ -12,6 +12,7 @@ import com.base.locationsharewhite.fcm.PopupConstObject.popup_battery_interval
import com.base.locationsharewhite.helper.EventUtils
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.KotlinExt.currentDate
import kotlin.math.absoluteValue
/**
*电量监听
......@@ -99,6 +100,8 @@ class BatteryStatusReceiver() : BroadcastReceiver() {
}
private var currentBatteryPercentage = 0f
override fun onReceive(context: Context, intent: Intent?) {
val action = intent?.action
if (action == Intent.ACTION_BATTERY_CHANGED) {
......@@ -106,11 +109,15 @@ class BatteryStatusReceiver() : BroadcastReceiver() {
val batteryScale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
val batteryPercentage = (batteryLevel / batteryScale.toFloat()) * 100
if (batteryPercentage < 21) {
//避免频繁触发
val changeValue = currentBatteryPercentage - batteryPercentage
if (batteryPercentage < 21 && changeValue.absoluteValue >= 1f) {
//推送次数没有达到限制并且展示的最小时间间隔大于配置时间(分钟)
NotificationUiUtil.sendNotificationIfCan(context, where = POPUP_WHERE_BATTERY)
NotificationUiUtil.sendNotificationIfCan(context, POPUP_WHERE_BATTERY, null)
}
currentBatteryPercentage = batteryPercentage
}
}
......
......@@ -31,7 +31,7 @@ class ScreenStatusReceiver : BroadcastReceiver() {
if (isDeviceInteractive && !isSecureLockActive) {
val secureSetting = AppPreferences.getInstance().getString(lockS, "1").toInt()
if (secureSetting == 1) {
sendNotificationIfCan(context, PopupConstObject.POPUP_WHERE_LOCK, null)
sendNotificationIfCan(context, POPUP_WHERE_LOCK, null)
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment