android - 打瞌睡模式、电池优化白名单、AlarmManager 频率超过 9 分钟

标签 android alarmmanager android-doze

我正在创建一个应用程序来连接 BT 设备以收集健康数据(即:体温)。

传感器周期性休眠,仅在有限的时间窗口内唤醒以进行连接。

我尝试创建 AlarmManager,它使用 setExactAndAllowWhileIdle() 触发前台服务,并且它在超过 9 分钟的时间内按预期工作,

但低于 9 分钟它会进入休眠模式并且不会触发 AlarmManager BroadcastReceiver。

根据文档,我不明白将应用程序添加到电池优化白名单是否会允许 AlarmManager 更频繁地触发 https://developer.android.com/training/monitoring-device-state/doze-standby#support_for_other_use_cases

For example, the whitelisted app’s jobs and syncs are deferred (on API level 23 and below), and its regular AlarmManager alarms do not fire

什么是常规警报? setExactAndAllowWhileIdle() 是常规的吗?

任何澄清将不胜感激

编辑:

我知道 setExactAndAllowWhileIdle() 会在休眠模式下触发事件超过 9 分钟,问题是将应用程序添加到白名单是否会允许它更频繁地触发

最佳答案

What are the regular alarms ? is setExactAndAllowWhileIdle() regular ?

没有。 setExactAndAllowWhileIdle() 不正常。常规警报可以是通过 setExact() 和 setWindow() 设置的 AlarmManager 警报。

but below 9 minutes it goes to doze mode and do not fire AlarmManager BroadcastReceiver

它对设置闹钟的频率有限制。

基于documentation :

To reduce abuse, there are restrictions on how frequently these alarms will go off for a particular application. Under normal system operation, it will not dispatch these alarms more than about every minute (at which point every such pending alarm is dispatched); when in low-power idle modes this duration may be significantly longer, such as 15 minutes.

可以引用Doze restrictions其中说:

Standard AlarmManager alarms (including setExact() and setWindow()) are deferred to the next maintenance window.

  • If you need to set alarms that fire while in Doze, use setAndAllowWhileIdle() or setExactAndAllowWhileIdle().
  • Alarms set with setAlarmClock() continue to fire normally — the system exits Doze shortly before those alarms fire

对于白名单:

白名单中可用的应用部分免于打瞌睡和应用待机优化。这并不意味着他们可以完全访问并可以在打瞌睡模式下执行任务。列入白名单的应用程序可以使用网络并在打盹和应用程序待机期间保持部分唤醒锁定。然而,其他限制,如工作不同,标准警报触发仍然强加

注意:您应该 check acceptable usecases用于将应用列入白名单。

Google Play policies prohibit apps from requesting direct exemption from Power Management features in Android 6.0+ (Doze and App Standby) unless the core function of the app is adversely affected.

关于android - 打瞌睡模式、电池优化白名单、AlarmManager 频率超过 9 分钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51399353/

相关文章:

java - 当我在早些时候或午夜之后设置闹钟时,Android 闹钟会立即触发

android - PendingIntent 上的 "requestCode"用于什么?

android - AlarmManager 不播放选定的音调

java - Android Oreo,wifiManager.getScanResults() 在 Doze 中返回空列表

android - 找不到 'com.android.support:design:22.2.0'

c# - 应用程序不会在其他计算机上运行/打开

android - Google 登录 Android 应用程序以使用 Cloud Endpoints 后端

android - 根据语言选择对齐 TextView (左 - 右)

android - 如何以编程方式关闭棉花糖设备中特定应用程序的打瞌睡模式

android - 当应用程序处于后台时如何保持 GPS 接收器位置更新(Google Play 服务位置 API)