防止用户解除通知

时间:2013-08-27 12:01:10

标签: android notifications android-notifications dismiss

有些应用会通过滑动来解除通知。

我该如何管理这种行为?

3 个答案:

答案 0 :(得分:104)

除了Andro Selvas回答:

如果您使用 NotificationCompat.Builder just use

builder.setOngoing(true);

答案 1 :(得分:39)

使用标记FLAG_ONGOING_EVENT使其持久化。

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

您也可以查看FLAG_NO_CLEAR

答案 2 :(得分:0)

我使用以下代码使通知持久存在:

  

startForeground(yourNotificationId,notificationObject);

要使其不被使用,只需执行以下操作:

  

stopForeground(true);

相关问题