【问题标题】:Oreo: Stop notification from getting removed on swipe奥利奥:阻止通知在滑动时被删除
【发布时间】:2018-10-29 09:19:23
【问题描述】:

我的代码:

mNotifyBuilder.setSmallIcon(R.drawable.ic_status_bar)
                .setContentTitle("")
                .setOngoing(true)
                .setAutoCancel(false)
                .setTicker("")
                .setColor(ContextCompat.getColor(mContext, R.color.folderlist_bg_music))
                .setChannelId(CHANNEL_ID)
                .setContent(remoteViews).build();

在其他手机上运行良好,但在 Vivo V7 上无法运行。 在第一次滑动时,通知被删除并重新出现。但是在第二次滑动时,它完全消失了。

【问题讨论】:

标签: android android-notifications android-8.0-oreo


【解决方案1】:

选项 1: 您需要按照以下方式进行操作:

builder.setOngoing(true);

选项 2:

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

选项 3:

NotificationCompat.Builder mBuilder =

                     new NotificationCompat.Builder(this)

                    .setSmallIcon(R.drawable.ic_service_launcher)

                    .setContentTitle("My title")

                    .setOngoing(true)  

                    .setContentText("Small text with details");

【讨论】:

  • 在其他手机上运行良好,但在 Vivo V7 上无法运行。
  • 老实说,我对 Vivo 非常失望,他们的操作系统实际上非常难以预测。其他应用程序将无法做到这一点。如果您希望应用程序正常工作,您需要锁定应用程序。 vivo一般会关闭应用的后台服务。您可以尝试安装任何行为相同的警报应用程序。连报警器都不起作用。 :(
  • Vivo 的行为对于 Microsoft 应用程序也非常不确定。甚至 Outlook 应用程序也无法正常工作。
  • 我建议不要在 Vivo 上浪费你的时间
  • 嗨@user1517153,如果您觉得这个答案对其他人有帮助,请接受它作为答案,和/或如果您觉得它有帮助,请点赞。
【解决方案2】:

启动一个虚拟前台Service ...这将在通知运行时保持通知。

前台服务执行一些用户可以注意到的操作。例如,音频应用程序将使用前台服务来播放音轨。前台服务必须显示通知。即使用户没有与应用交互,前台服务也会继续运行。

【讨论】:

  • 在其他手机上运行良好,但在 Vivo V7 上无法运行。
  • @user1517153 这可能是一个糟糕的奥利奥构建;人们也抱怨显示驱动程序......可能它也可能有一个特定于供应商的通知系统;例如。和 MIUI 一样。
  • 这将是支持论坛:bbs.vivo.com.cn/forum-152-1.html
【解决方案3】:

尝试添加这个:

notification.flags |= Notification.FLAG_NO_CLEAR;

【讨论】:

    【解决方案4】:

    您可以尝试以下方法:

    builder.setOngoing(true); // Can't cancel your notification (except notificationManager.cancel(); )
    

    参考这个Ongoing notification

    【讨论】:

    【解决方案5】:

    这是手机特有的问题。同样的事情适用于其他手机,但不适用于 Vivo 手机。 OEM 不应偏离现有 Android 提供的基本实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多