I have a public class to make notifications…
public class notifyHelper {
public void sendNotification(Activity caller, Class<?> activityToLaunch, String title, String msg, int numberOfEvents, boolean flashLed, boolean vibrate, int ID) {
NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE);
// Create this outside the button so we can increment the number drawn over the notification icon.
// This indicates the number of alerts for this event.
long whenTo = System.currentTimeMillis() + (1000 * 60 * 15);
final Notification notify = new Notification(R.drawable.icon, "", whenTo);
notify.icon = R.drawable.icon;
notify.tickerText = "TV Spored ++";
notify.when = whenTo;
notify.number = numberOfEvents;
notify.flags |= Notification.FLAG_AUTO_CANCEL;
if (flashLed) {
// add lights
notify.flags |= Notification.FLAG_SHOW_LIGHTS;
notify.ledARGB = Color.CYAN;
notify.ledOnMS = 500;
notify.ledOffMS = 500;
notify.defaults |= Notification.DEFAULT_SOUND;
}
if (vibrate) {
notify.vibrate = new long[] {100, 200, 200, 200, 200, 200, 1000, 200, 200, 200, 1000, 200};
}
Intent toLaunch = new Intent(caller, activityToLaunch);
PendingIntent intentBack = PendingIntent.getActivity(caller, 0, toLaunch, 0);
notify.setLatestEventInfo(caller, title, msg, intentBack);
notifier.notify(ID, notify);
}
public static void clear(Activity caller) {
NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE);
notifier.cancelAll();
}
}
No matter what I do (look whenTo) this notification is always shown when called… How can I set notification time?
Thanks for the answer!
What makes you think there’s a way to create a notification that is not immediate?
From http://developer.android.com/reference/android/app/Notification.html you can see a few important things. First, the constructor you’re using is deprecated — you should look to using http://developer.android.com/reference/android/app/Notification.Builder.html instead. More importantly though, the 3rd parameter is not “when to show the notification”, its the time to display in the time field of the notification itself. To visualize this… call your phone and don’t answer (in order to cause a missed call notification). Then pull down your notification drawer and notice the time that gets displayed in the lower right.