我点击了这个链接 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/