如何将日期列表转换为 AlarmManager?
我有一个大约 20 个日期的列表,所有格式都类似于
August 24,2011
我如何创建所有这些日期的列表并将它们设置到警报管理器,
例如...今天是 25,如果 AlarmManager 中的日期是设置为 25,会发出通知。
我该怎么做呢?
I have a list of about 20 dates all formated like
August 24,2011
How would i go about creating a list of all of these dates and setting them to the alarm manager,
So for example... Today is the 25, if a date in the AlarmManager is set to 25, a notification is made.
How would i go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先使用格式化程序转换为日期。然后使用 getTime()< 从日期对象获取时间戳/a>.将时间戳传递给
AlarmManager
并指定RTC
或RTC_WAKEUP
闹钟类型。例如:请记住,警报不是持久的,因此将警报设置在未来太远是不可靠的:如果用户重新启动您的手机(或终止您的应用程序/服务),警报将被清除。要在重新启动时注册警报,请为
BOOT_COMPLETED
创建广播接收器。Convert to a date first, using a formatter. Then get the timestamp from the date object using getTime(). Pass the timestamp to
AlarmManager
and specify theRTC
orRTC_WAKEUP
alarm type. Something like:Do keep in mind that, alarms are not persistent, so setting alarms too far in the future is not reliable: if the user reboots your phone (or kills your app/service), the alarms will be cleared. To register alarms on reboot, create a broadcast receiver for
BOOT_COMPLETED
.