Prevent user from dismissing notification

2019-03-14 05:48发布

Some apps have notifications which can´t be dismissed by swiping them away.

How can I manage such behaviour?

3条回答
Bombasti
2楼-- · 2019-03-14 06:03

In addition to Andro Selvas answer:

If you are using the NotificationCompat.Builder, just use

builder.setOngoing(true);
查看更多
可以哭但决不认输i
3楼-- · 2019-03-14 06:05

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

查看更多
Deceive 欺骗
4楼-- · 2019-03-14 06:08

I used the below code to make my notification persistent:

startForeground(yourNotificationId,notificationObject);

To make it dismissable, just do the below:

stopForeground(true);

查看更多
登录 后发表回答