通过AlarmManager 设置不准确的警报时会有多少延迟?

How much delay is there when setting an inexact alarm via AlarmManager?

使用AlarmManager设置闹钟时,除非您设置了准确的闹钟,否则在指定时间之后的某个时间触发闹钟可能会有延迟。是否可以保证此延迟的范围?我想成为一名负责任的开发人员,如果延迟不超过一分钟,我不会使用确切的时间。但是我找不到关于文档延迟的任何规范。如果有记录延迟功能及其时间规范的资源,我将不胜感激。

75% of either the recurrence interval [for a periodic alarm] or of the time from now to the desired delivery time, with a minimum delay/interval of 10 seconds, under which we will simply not defer the alarm.

来自 API19 的 AlarmManagerService 的 Android 来源(仍然与 API23 相同)

   Requested    Batch Window
     1 Mins  ->  1- 1¾ Mins
    10 Mins  -> 10-17½ Mins
    30 Mins  -> 30-52½ Mins
     1 Hour  ->  1- 1¾ Hours

还值得注意的是,虽然 AlarmManagerService 会保护 window 长度以确保超过半天的长度被视为可疑(并重写为 1 小时),但它不提供类似的健全性检查触发次数。

因此,您可以轻松地提供基于 RTC 的值 (System.currentTimeMillis()) 和基于经过的模式 (ELAPSED_REALTIME),并以未来数千年的警报结束.