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

标签 java android firebase push-notification notifications

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

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

最佳答案

通过生成一个随机数作为 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);
}

关于java - 新的 Firebase 通知替换现有的未读 Firebase 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44735673/

相关文章:

java - Spring可缓存不同步

android - getChildView 未被调用

android - 在 android 中禁用 google ML Kit 库的 firebase 日志记录

java - setOnitemSelectedListener 执行一些查询后微调器消失

java - 如何理解 Guava 缓存统计指标?

Java 数据库显示国家数据库表中的所有国家信息

javascript - 使用javascript关闭移动浏览器选项卡

android - Flutter Firebase : Heads up notification not showing on background

java - 如何使用 BigInteger 和小数?

java - 使用数组时出现 NullPointerException