如何获取在关闭和打开移动设备之间传递的警报通知
你好 我正在开发一个应用程序,其中使用 AlarmManager
问题
当我在特定日期和时间使用警报管理器设置挂起意图时,它工作正常 但假设我将闹钟时间设置为日期 30-05-2011 和时间 10:00 AM 并假设当前时间是日期 30-05-2011 和时间 09:50 AM 现在,在创建挂起意图后,我关闭了设备,并在上午 10:01 后启动了设备 当时我希望收到 10:00 AM 闹钟的通知,但我没有收到 知道如何在打开手机后收到通知吗
Hi
I am developing a application in which i am using AlarmManager
Problem
When i set pending Intent using Alarm manager on perticular date and time its work fine
but suppose i set alarm time on date 30-05-2011 and time 10:00 AM and suppose current time is date 30-05-2011 and time 09:50 AM
and now after creating pending intent i switched off my device and after 10:01 AM i starts my device
at that time i expect notification for 10:00 AM alarm but i am not getting it
Any idea how i can get notification After switch on my mobile
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过AlarmManager,您只能在设备休眠时唤醒设备。
要做到这一点,请使用
setRepeating(int类型,长triggerAtTime,长间隔,PendingIntent操作)
或 set(...)
与 RTC_WAKEUP 或 ELAPSED_REALTIME_WAKEUP
但它不适用于关闭的设备。
因此,您应该考虑将闹钟以及应用程序上次打开的时间存储在数据库中,并计算自上次起床以来错过的闹钟数量。
问候,
史蒂芬
Through AlarmManager, you can only wake up your device when it is sleeping.
To do that use
setRepeating(int type, long triggerAtTime, long interval, PendingIntent operation)
or set(...)
with RTC_WAKEUP or ELAPSED_REALTIME_WAKEUP
But it doesn't work with a device at off.
So you should consider having your alarms in a database, along with the last time your app was on, and count the alarms you missed since last time you were up.
Regards,
Stéphane
如果您阅读 AlarmManager API 文档页面:
作为替代方案,您可以为意图
android.intent.action.BOOT_COMPLETED
注册广播接收器,并在需要执行操作时检查您的 SharedPreferences。有关广播的详细信息,请参阅此问题:尝试启动服务在 Android 上启动时
If you read the AlarmManager API doc page:
As an alternative, you can register a broadcast receiver for the intent
android.intent.action.BOOT_COMPLETED
and check your SharedPreferences if you need to perform an action.See this question for details about the broadcast: Trying to start a service on boot on Android