开发者

Android Delayed Notification

I am trying to create a Notification using Android's Notification Manager, however, the trick is that I want the notification to show up 30 days in the future. In my code I'm doing this:

Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
long when = System.currentTimeMillis() + (30 * 24 * 3600 * 1000);
Notification notification = new Notification(R.drawable.some_image, "A title", when);
notification.setLatestEventInfo(getApplicationContext(), "You're late", "Some description", contentIntent);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(NOTIFY_ATTEND_ID, notification);

However, the notification is still showing up instantaneously. From what I read, the "when" parameter to the Notification cons开发者_如何学JAVAtructor is only used to sort the notifications in the StatusBar. Is there anyway to make the notification show up in at a future date/time? Thanks in advance.


Is there anyway to make the notification show up in at a future date/time?

No.

As Falmarri suggests, you will need to handle this yourself, though I disagree with his approach. You will need to use AlarmManager. However, I am skeptical that AlarmManager will work for 30-day durations, though you can try it. You may need to use AlarmManager for a daily/weekly task to schedule that day's/week's notifications via separate alarms. You will also need to reconstitute this roster of alarms on a reboot, since they get wiped, as Falmarri suggests.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜