0

I'm struggling to get my FCM notifications to stack in the same way as for Whatsapp:

1) The latest message for a particular room is displayed, with an updated count of all unread messages.

2) Indicating separate groupings of point 1 for notifications for different rooms.

I have spent a few hours looking at various SO questions and this is the closest I've come to finding an answer. The issue is that I am using a data payload, not notification, and it doesn't seem like the "tag" property works for my data payload.

The current behavior is that only the latest notification shows, overriding the previous.

Here is the sendNotification() method in my FirebaseMessagingService

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());
    }
Christopher Mills
  • 711
  • 10
  • 28
  • Have you tried different IDs? as long as the ID is the same it will be replaced. Hopefully that's helpful. – TheBen Aug 26 '18 at 21:55
  • @TheeBen Setting different ids does do the trick of creating separate notifications. However, I'm still not winning in terms of the behavior outlined in the linked question. Specifically, the behavior suggested when setting the 'tag' property in the data payload, which results in a message count within a single notification. – Christopher Mills Aug 27 '18 at 16:42

0 Answers0