开发者

Android : AlarmManager with defined date

开发者 https://www.devze.com 2023-04-01 11:07 出处:网络
If I set my AlarmManager like this : am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 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 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); 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号