tsiro
tsiro

Reputation: 2403

ongoing notification is dismissible

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

Answers (1)

Appafly
Appafly

Reputation: 666

Try this:

notification.flags = Notification.FLAG_NO_CLEAR;

Upvotes: 1

Related Questions