13

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 constructor 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.

Jeff
  • 161
  • 2
  • 5
  • Making it show up 30 days in the future is not trivial. Alarms and such get killed on bootup. You'd have to keep a service up or something – Falmarri Nov 03 '10 at 06:05

1 Answers1

4

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for the advice Commons. I'll take a look at the AlarmManager and see if that will do the trick. Since I am also running an SQLite database in this application, I can store some of the notification information there. I'll let ya'll know how it goes. – Jeff Nov 04 '10 at 03:32
  • Thanks again Falmarri and CommonsWare. Your solutions worked for me. I ended up following the AlarmController API Demo: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlarmController.html. – Jeff Nov 05 '10 at 15:11