I'm launching a notification on the weekend. If the notification is not seen/clicked after a certain time, I would like it to disappear by itself.
I couldn't find any way to set a timeout or something of the sort within the NotificationCompat.Builder
expression. Here is the (quite normal notification builder) code:
Intent myIntent = new Intent(context, MyActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.not_bar_small_icon)
.setColor(ContextCompat.getColor(context, R.color.Green))
.setContentTitle(context.getResources().getString(R.string.strNotificationTitle))
.setContentText(context.getResources().getString(R.string.strNotificationMessage))
.setContentIntent(pendingIntent);
NotificationManager notifyManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
notifyManager.notify(MY_NOTIFICATION_ID, mBuilder.build());
Can this be done?
Solution Update:
Solved using Aleksandar's link suggested in the comment below.