setExactAndAllowWhileIdle - 与开发人员参考不完全相同 [英] setExactAndAllowWhileIdle - is not exact as of developer reference

查看:52
本文介绍了setExactAndAllowWhileIdle - 与开发人员参考不完全相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AlarmManager 具有方法 setExact() 来设置准确的警报.

AlarmManager on API19 has the method setExact() to set an exact alarm.

确切的意思 --> 如果我将闹钟设置为下午 2:01,它将在下午 2:01 触发

Exact means --> If I set an alarm to 2:01 pm it will be triggered at 2:01 pm

API 23 - Marhsmwallow (6.0) 上有一个新方法 setExactAndAllowWhileIdle(),但作为参考,它不是 EXACT,因为它只会触发 >每分钟,在低功耗空闲模式下仅每 15 分钟.

On API 23 - Marhsmwallow (6.0) there is a new method setExactAndAllowWhileIdle(), but as of the reference it is not EXACT because it will trigger only every minute and in low power idle mode only every 15 minutes.

精确 != 每 15 分钟 :-)

那么如何在 6.0 中使用 AlarmManager 实现精确警报?

So how can I achieve an exact alarm with AlarmManager in 6.0?

如果用户添加提醒或日历约会并希望在事件发生前 10 分钟收到通知,则应在事件发生前精确 10 分钟显示警报.使用 setExactAndAllowWhileIdle() 这似乎是不可能的.

If a user adds a reminder or a calendar appointment and wants to be informed 10 minutes before the event it should show the alarm EXACT 10 minutes before the event. With setExactAndAllowWhileIdle() this seems is not possible.

参考链接:http://developer.android.com/reference/android/app/AlarmManager.html#setExactAndAllowWhileIdle(int, long, android.app.PendingIntent)

推荐答案

那么如何在 6.0 中使用 AlarmManager 实现准确的警报?

So how can I achieve an exact alarm with AlarmManager in 6.0?

欢迎您尝试 setAlarmClock(),因为AFAIK它不受打盹模式的影响.否则,AlarmManager 对您来说不是一个可行的选择.即使将您的应用列入电池优化白名单也无济于事,因为 AlarmManager 行为不会根据白名单而改变.

You are welcome to try setAlarmClock(), as AFAIK it is unaffected by Doze mode. Otherwise, AlarmManager is not a viable option for you. Even having your app on the battery optimization whitelist will not help, as AlarmManager behavior does not change based on the whitelist.

欢迎您使用 GCM,因为高优先级消息应该让您有机会提醒用户.当然,这需要网络连接.

You are welcome to use GCM, as a high-priority message should give you an opportunity to alert the user. This, of course, requires network connectivity.

我所知道的唯一离线解决方案—并且我目前正在测试—是让用户将您的应用程序添加到电池优化白名单,然后使用前台服务(尝试保留您的进程)、ScheduledExecutorService(用于计时)和部分 WakeLock(保持 CPU 开启).这将对用户的电池造成相当大的破坏.

The only offline solution that I am aware of — and that I am presently testing — is to have the user add your app to the battery optimization whitelist, then use a foreground service (to try to keep your process around), a ScheduledExecutorService (for the timing), and a partial WakeLock (to keep the CPU on). This will be fairly devastating to the user's battery.

这篇关于setExactAndAllowWhileIdle - 与开发人员参考不完全相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆