Android:具有定义日期的 AlarmManager
如果我像这样设置 AlarmManager :
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), sender);
它可以工作,并且在我创建它后立即启动通知。
但我想要的是在定义的日期和时间启动通知,但它不起作用。 这是我的代码的一些部分:
我希望启动通知的时间:(
Date dateNotif = null;
dateNotif = new Date (mYear, mMonth, mDay, mHour, mMinute);
以“m”开头的变量是来自 DatePicker 和 TimePicker 的整数。值可以是,例如 2011, 8, 31, 16 , 45)
AlarmManager 的设置:
am.set(AlarmManager.RTC_WAKEUP, dateNotif.getTime(), sender);
我对此没有任何错误,但没有启动任何通知...
但似乎模拟器在此后几分钟内不再应答。
谢谢你的帮助。
If I set my AlarmManager like this :
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), sender);
It works and notification is launched as soon as I create it.
But what I want is to launch a notification at a defined date and time but it doesn't work.
Here is some parts of my code :
The time when I want the notification to get launched :
Date dateNotif = null;
dateNotif = new Date (mYear, mMonth, mDay, mHour, mMinute);
(Variables starting by "m" are integer coming from a DatePicker and a TimePicker. Values can be, for exemple, 2011, 8, 31, 16, 45)
Settings of the AlarmManager :
am.set(AlarmManager.RTC_WAKEUP, dateNotif.getTime(), sender);
I have no mistakes with this but no notification is launched...
But it seems that the emulator doesn't answer anymore few minutes after this.
Thx for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于 Date 预计自 1900 年以来的年份,因此当您给出 2011 年时,实际上是 3911 年。尝试:
I think the problem is that Date expects years since 1900, so when you give it 2011 that is actually the year 3911. Try: