Android 如何以Whatsapp样式堆叠或分组Firebase云消息通知
我正在努力让我的FCM通知以与Whatsapp相同的方式堆叠: 1) 将显示特定房间的最新消息,以及所有未读消息的更新计数 2) 为不同房间的通知指示点1的单独分组 我花了几个小时研究各种SO问题,这是我最接近找到答案的一次。问题是我使用的是数据负载,而不是通知,而且“tag”属性似乎不适用于我的数据负载 当前的行为是,仅显示最新的通知,覆盖以前的通知 以下是myAndroid 如何以Whatsapp样式堆叠或分组Firebase云消息通知,android,firebase,push-notification,firebase-cloud-messaging,Android,Firebase,Push Notification,Firebase Cloud Messaging,我正在努力让我的FCM通知以与Whatsapp相同的方式堆叠: 1) 将显示特定房间的最新消息,以及所有未读消息的更新计数 2) 为不同房间的通知指示点1的单独分组 我花了几个小时研究各种SO问题,这是我最接近找到答案的一次。问题是我使用的是数据负载,而不是通知,而且“tag”属性似乎不适用于我的数据负载 当前的行为是,仅显示最新的通知,覆盖以前的通知 以下是myFirebaseMessagingService中的sendNotification()方法 private void sendNot
FirebaseMessagingService中的sendNotification()方法
private void sendNotification(RemoteMessage remoteMessage) {
//Intent intent = new Intent(this, StudentChatActivity.class);
String clickAction = remoteMessage.getData().get("click_action");
Intent intent = new Intent(clickAction);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
String roomID = remoteMessage.getData().get("ROOMID");
String origin = remoteMessage.getData().get("ORIGIN");
String msgID = remoteMessage.getData().get("MSGID");
Log.d(TAG, "Message data payload, roomID: " + roomID);
intent.putExtra("ROOMID", roomID);
intent.putExtra("USERID", UserID);
intent.putExtra("USERNAME", UserName);
intent.putExtra("ORIGIN", origin);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
String channelId = getString(R.string.received_message);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.small_pickle)
.setContentTitle("FCM Message")
.setContentText(remoteMessage.getData().get("body"))
.setPriority(1)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Since android Oreo notification channel is needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId,
"Channel human readable title",
NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(channel);
}
Log.d(TAG, "Noification ID: " + notify_no);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
你试过不同的身份证吗?只要ID相同,它就会被替换。希望这会有所帮助。@TheeBen设置不同的ID确实可以创建单独的通知。然而,就链接问题中概述的行为而言,我仍然没有获胜。具体来说,在数据有效负载中设置“tag”属性时建议的行为,这将导致单个通知中的消息计数。