【问题标题】:How to disable multiple push Notification icon in Android, Am using Parse.com如何在 Android 中禁用多个推送通知图标,我正在使用 Parse.com
【发布时间】:2014-09-05 14:07:01
【问题描述】:

Android 应用程序的 com 推送通知,一切运行良好,但假设我每天发送 5 个推送通知,我不希望用户在他的手机上一次看到 5 个通知图标。最好他只看到一个。他们删除旧通知并只显示最新通知的任何方式也是如此。

【问题讨论】:

    标签: android push-notification parse-platform google-cloud-messaging


    【解决方案1】:
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    

    显示通知的方法有一个表示通知标识符的 int 参数。如果您使用常量标识符,则每个新通知都会替换之前的通知。

    【讨论】:

      【解决方案2】:

      您必须将通知 ID 设置为相同的值。因此,它们会在每个到达时被替换。

      【讨论】:

      • 关于如何设置相同通知 ID 的任何帮助。
      • 您必须显示有关如何显示通知的代码。这可能与@Eran 回复的内容非常相似。
      • 只选择一个数字并坚持下去?通知 ID 不变的唯一问题是它会覆盖现有通知,因此您必须确保它确实是您想要的(旧的会被忽略)。
      【解决方案3】:

      int notificationId = 1 ;

      NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

          builder.setAutoCancel(true);
          builder.setSmallIcon(R.drawable.gcm_logo);
          builder.setContentTitle("Test Title");
          builder.setContentIntent(pendingIntent);
          NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
          notificationManager.notify(notificationId, builder.build());
      

      因此您可以为不同类型的通知维护通知 ID。如果您为每个通知保留相同的通知 ID,那么它将在相同的 .

      如果您在待定意图中有任何附加内容,并且您想用最新的内容更新这些附加内容,则使用以下命令生成待处理意图:

      PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), PendingIntent.FLAG_ONE_SHOT);

      【讨论】:

        猜你喜欢
        • 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
        相关资源
        最近更新 更多