防止用户解除通知

Mar*_*ies 59 notifications android dismiss android-notifications

某些应用程序的通知无法通过滑动来解除.

我该如何管理这种行为?

Mar*_*ies 112

除了Andro Selvas回答:

如果您使用的是NotificationCompat.Builder,请使用

builder.setOngoing(true);
Run Code Online (Sandbox Code Playgroud)

  • 我更喜欢这个答案,只是因为我正在使用 Builder。 (2认同)

And*_*lva 39

使用标志,FLAG_ONGOING_EVENT使其持久化.

Notification notification = new Notification(icon, tickerText, when);
    notification.flags = Notification.FLAG_ONGOING_EVENT;
Run Code Online (Sandbox Code Playgroud)

您也可以查看FLAG_NO_CLEAR