【问题标题】:I need to delete android notification badges我需要删除 android 通知徽章
【发布时间】:2018-12-02 04:08:29
【问题描述】:

我没有处理通知徽章的代码,并且在 Android 开发者网页上显示:“...您的应用无需执行任何操作...”

https://developer.android.com/training/notify-user/badges

问题是徽章出现后,当我直接进入应用程序时它并没有消失。 看起来我的应用程序中需要更多代码。 知道发生了什么吗?

所有这些都在 Android Oreo 中。

【问题讨论】:

    标签: android notifications badge android-8.1-oreo


    【解决方案1】:

    只要显示该应用的通知,就会显示该应用图标上的徽章。

    您可以为您的通知设置 autoCancel 为 true,或者您可以通过 NotificationManager 以程序方式取消您的应用程序的任何通知,当应用程序变为活动状态时,即在您的通知导致的活动的 onStart 或 onResume 中。

    【讨论】:

      【解决方案2】:

      您也可以在构建通知渠道时选择完全不显示徽章:

      /**
       * Sets whether notifications posted to this channel can appear as application icon badges
       * in a Launcher.
       *
       * Only modifiable before the channel is submitted to
       * {@link NotificationManager#createNotificationChannel(NotificationChannel)}.
       *
       * @param showBadge true if badges should be allowed to be shown.
       */
      public void setShowBadge(boolean showBadge) {
          this.mShowBadge = showBadge;
      }
      

      【讨论】:

      • 是的,这是我认为的选项之一,但顶部栏中的通知仍将保留,因此,现在我正在寻找有关如何在用户打开时以编程方式取消通知的信息应用程序。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多