Android 6.0 中设置闹钟的精确方法

Precise method to set alarms in Android 6.0

setAlarmclock(), setAndAllowWhileIdle()setExactandAllowWhileIdle() 是文档中描述的方法,可以让闹钟摆脱打瞌睡和应用程序待机模式。

但是,有多个使用 Google Clock that the alarm did not work on their devices (Google Clock uses setAlarmclock() with setExact() 方法的 nexus 用户报告。

setAndAllowWhileIdle() 已被 报道 不影响打瞌睡模式,而 setExactandAllowWhileIdle() 据说工作,但只有 15 分钟的间隔。

我需要能够以至少 5 分钟的间隔安排闹钟。正确的方法应该是什么?

我最近 found that an alarm set with setAlarmClock keeps the device from entering IDLE mode within 2 hours of the alarm setting off. It seems like using setAlarmClock with setExactAndAllowWhileIdleMarshmallow 上的最佳方法。

据我所知,您的每 5 分钟触发一次警报的问题没有解决方案。您将无法根据您的要求切断打瞌睡模式。你必须想办法增加报警时间。此外,根据 "Acceptable Use Cases for Whitelisting".

,将 GCM 消息用于非消息应用程序可能会导致违规

此外,您无法在设备处于休眠模式时设置重复闹钟。您必须使用上述 API 设置闹钟,并在闹钟响起时重新注册!