NotificationCompat at a time

Viewed 808

I want to show notification at defined time. I use "setWhen()". But any argument of setWhen() is ignoring and notification always showing instantly. What I did wrong? My code:

NotificationCompat.Builder mBuilder =
    new NotificationCompat.Builder(this)
                    .setWhen(???)
                    .setSmallIcon(R.drawable.app_icon)
                    .setContentTitle("Test")
                    .setContentText("Test");
    Intent resultIntent = new Intent(this, MainActivity.class);

    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, mBuilder.build());
2 Answers

That's not the purpose of setWhen. It's only a UI thing, if setShowWhen is enabled this timestamp is shown at the notification.

For your purpose, I would suggest the android AlarmManager. An example can be found here

setWhen() is used to show the time on the notification itself, not when the notification is shown.

The time on the top right of the notification is what setWhen() controls:

enter image description here

For showing the notification at a particular time, you can use the AlarmManager class. This has code to do the same.

Related