新的 Firebase 通知替换现有的未读 Firebase 通知

Posted

技术标签:

【中文标题】新的 Firebase 通知替换现有的未读 Firebase 通知【英文标题】:New Firebase notification replacing existing unread Firebase Notification 【发布时间】:2017-06-24 11:00:00 【问题描述】:

我点击了这个链接Firebase Notification,可以将通知发送到单个设备和多个设备。但是,新到达的通知正在替换托盘中已经存在的未读通知。请告诉我一种停止这种情况并在托盘中显示所有未读通知的方法。

注意:教程是关于 GCM 的。我为 FCM 做了必要的更改。

【问题讨论】:

添加这个 setAutoCancel(false) @NancyY 不,不工作。还是一样 【参考方案1】:

通过生成一个随机数作为 id 并在 notify() 方法中提供它来解决问题

 public void showSmallNotification(String title, String message, Intent intent) 
    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                    mCtx,
                    ID_SMALL_NOTIFICATION,
                    intent,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );


    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx);
    Notification notification;
    notification = mBuilder.setSmallIcon(R.mipmap.ic_launcher).setTicker(title).setWhen(0)
            .setAutoCancel(true)
            .setContentIntent(resultPendingIntent)
            .setContentTitle(title)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher))
            .setContentText(message)
            .build();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    Random random = new Random();
    int m = random.nextInt(9999 - 1000) + 1000;


    NotificationManager notificationManager = (NotificationManager)     mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(m, notification);

【讨论】:

以上是关于新的 Firebase 通知替换现有的未读 Firebase 通知的主要内容,如果未能解决你的问题,请参考以下文章