【问题标题】:Prevent user from dismissing notification防止用户关闭通知
【发布时间】:2013-08-30 03:55:39
【问题描述】:

有些应用的通知无法通过滑动来关闭。

我该如何管理这种行为?

【问题讨论】:

    标签: android notifications android-notifications dismiss


    【解决方案1】:

    除了 Andro Selvas 回答:

    如果您使用的是NotificationCompat.Builderjust use

    builder.setOngoing(true);
    

    【讨论】:

    • 我更喜欢这个答案,只是因为我使用的是Builder。
    • 这对我不起作用。看起来它使通知没有“x”关闭按钮,但仍然可以完成滑动手势。
    • 使用 NotificationCompat 构建器为我工作。
    • 这不适用于华为手机,但适用于三星
    【解决方案2】:

    使用标志FLAG_ONGOING_EVENT 使其持久化。

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

    您也可以查看FLAG_NO_CLEAR

    【讨论】:

    • 谢谢,你拯救了我的一天。
    • 我尝试使用“setOngoing(true)”,但它对我不起作用。 “FLAG_ONGOING_EVENT”对我有用。
    【解决方案3】:

    我使用以下代码使我的通知持久化:

    startForeground(yourNotificationId,notificationObject);

    要让它消失,只需执行以下操作:

    stopForeground(true);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-11
      • 1970-01-01
      • 2018-09-23
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多