我正在使用FCM向Android设备发送通知.当应用程序处于后台时,如果我发送10个通知,则设备将在通知栏上显示10个条目.
我希望FCM在通知栏上只输入一个条目,即较新的条目将覆盖旧条目.我在https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream上找不到设置密钥的密钥.
有办法吗,或者不可能?谢谢.
android android-notifications firebase firebase-cloud-messaging firebase-notifications
我不确定这是否完全可能,但我会说明我的要求。如果可能的话请帮我弄清楚该怎么做。
假设我有一个类似画廊的 Android 应用程序。当用户对图库中的照片进行点赞或评论时,我们将使用下面给出的代码触发 fcm 通知
value++;
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification)
.setLargeIcon(rawBitmap)
.setContentTitle("MyApp")
.setContentText(ContentText)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setDefaults(Notification.DEFAULT_SOUND)
.setStyle(new NotificationCompat.BigTextStyle().bigText(ContentText))
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(value, notificationBuilder.build());
Run Code Online (Sandbox Code Playgroud)
通过添加 InboxStyle,我们可以将通知分组为一个通知,然后增加计数。(例如,您有 5 个通知)
NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle();
// Sets a title for the Inbox in expanded layout
inboxStyle.setBigContentTitle("Title - Notification");
inboxStyle.setSummaryText("You have "+value+" Notifications.");
notificationBuilder.setStyle(inboxStyle);
Run Code Online (Sandbox Code Playgroud)
但我的要求就像对单独的照片进行单独分组。如果用户为 3 张照片各留下 2 条评论。我需要列出三组通知。更像是您对这张照片有 2 条评论,对这张照片有 2 条评论,等等。
如果有帮助的话,我将收到照片的唯一 ID。
How long will the id be retained?
Run Code Online (Sandbox Code Playgroud)
假设用户对 ID 为 001 的照片发表了 2 …
android push-notification android-notifications firebase firebase-cloud-messaging