Android : AlarmManager with defined date
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 star开发者_运维知识库ting 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.
I think the problem is that Date expects years since 1900, so when you give it 2011 that is actually the year 3911. Try:
dateNotif = new Date (mYear - 1900, mMonth, mDay, mHour, mMinute);
精彩评论