Reputation: 2403
i would like to display a non dismissible notification and only dismiss it after some delay programmatically. I have tried the following:
RemoteViews bigView = new RemoteViews(context.getPackageName(),
R.layout.big_notification);
NotificationCompat.Builder builder = new
NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(text)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCustomHeadsUpContentView(bigView)
.setTicker("aaa")
.setOngoing(true);
notificationManager.notify(id, builder.build());
removeNotification(notificationManager, id);
}
private static void removeNotification(final NotificationManager notificationManager, final int id) {
Handler handler = new Handler();
long delayInMilliseconds = 4000;
handler.postDelayed(new Runnable() {
public void run() {
notificationManager.cancel(id);
}
}, delayInMilliseconds);
}
But the notification can be swiped out by the user...any thoughts?
Upvotes: 1
Views: 142