Prevent user from dismissing notification

核能气质少年 提交于 2019-12-02 21:01:21
Marian Klühspies

In addition to Andro Selvas answer:

If you are using the NotificationCompat.Builder, just use

builder.setOngoing(true);

Use the flag,FLAG_ONGOING_EVENT to make it persistent.

Notification notification = new Notification(icon, tickerText, when);
    notification.flags = Notification.FLAG_ONGOING_EVENT;

Also you can check, FLAG_NO_CLEAR

I used the below code to make my notification persistent:

startForeground(yourNotificationId,notificationObject);

To make it dismissable, just do the below:

stopForeground(true);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!