Android notification MessagingStyle grouping not working as expected

Viewed 103

I have MessagingStyle grouping notification working as expected until user logout and login again (Notification Sender User). Consider This Flow (Notification Sender):

User (Demo User) Send First Message -> Send Few More -> Logout from App -> Login Again With Other User ID -> Send Few Messages -> Logout -> Login Again With First User -> Send Message Again.

As you can see on receiver device the text message "Final" Shows as the separate user even when everything is same for Demo user. It should add into existing group of demo user message not as a new one. I don't understand why it's working like that.

enter image description here

   // SHOW NOTIFICATION TO USER START

        
        
        
        
        NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(),ChannelID);
        builder.setSmallIcon(R.drawable.launcher_x2);
        builder.setColor(getApplicationContext().getResources().getColor(R.color.green));
        builder.setChannelId(ChannelID);

        builder.setCategory(NotificationCompat.CATEGORY_MESSAGE);
        
        builder.setAutoCancel(true);
        NotificationCompat.MessagingStyle.Message  message;
        NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(UserName);

        Person person;

        if (Session.getFirebaseNotifications() != null ){
            Gson userData = new Gson();
            arrayListNotification = userData.fromJson(Session.getFirebaseNotifications(),
                    new TypeToken<ArrayList<PendingNotifications>>(){}.getType());
            arrayListNotification.add(0,new PendingNotifications(UserName,Message));
            int size = arrayListNotification.size();

            for (int i = size - 1; i >= 0; i--) {
                person = new Person.Builder()
                        .setName(arrayListNotification.get(i).getName())
                        .setIcon(IconCompat.createWithBitmap(getCircleBitmap(arrayListNotification.get(i).userImage)))
                        .setKey(arrayListNotification.get(i).getUserID())
                        .build();
                message =  new NotificationCompat.MessagingStyle.Message(
                        arrayListNotification.get(i).getMessage(),
                        Long.parseLong(arrayListNotification.get(i).getTime()),
                        person);
                messagingStyle.addMessage(message).setGroupConversation(true).setConversationTitle(arrayListNotification.size()+" New Messages");
            }
        }else{
            person = new Person.Builder()
                    .setName(UserName)
                    .setIcon(UserImage)
                    .setKey(UserID)
                    .build();
            message =
                    new NotificationCompat.MessagingStyle.Message(
                            resetMessage,
                            Long.parseLong(MsgObj.get(keyTimestamp)),
                            person);
            messagingStyle.addMessage(message).setGroupConversation(true).setConversationTitle("1 New Message");

            PendingNotifications pendingNotifications = new PendingNotifications(UserName,Message);
            arrayListNotification.add(pendingNotifications);

        }


        builder.setStyle(messagingStyle);
        builder.setTicker("Elaxer");
        saveNotification(arrayListNotification);
        builder.setGroup("com.example.group");
        managerCompat.notify(2,builder.build());
        

        // SHOW NOTIFICATION METHOD ENDS
0 Answers
Related