0


i have tried below lines of code to get the multiple notification lilke whatsapp but did not get solution please check my code and let me know where am i doing wrong?
I am using the fcm to achieve this, please help me to short out from this problem

Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Firebase Push Notification")
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent)
                .setNumber(4);


            numMessages=numMessages+1;

            for (int i = 0; i <= numMessages; i++) {
                notificationBuilder.setContentText(messageBody)
                        .setNumber(numMessages);
                NotificationManager notificationManager =
                        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

                notificationManager.notify(0, notificationBuilder.build());

            }

Please check the below image, in which i have showed that which type of group message i want to implement using FCM
enter image description here

Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103
  • Possible duplicate of [Android FCM notification grouping](http://stackoverflow.com/questions/39704562/android-fcm-notification-grouping) – AL. Nov 14 '16 at 13:29

2 Answers2

0

You're missing setGroup(). This function is to add all your notifications to a single group (grouped notification).

See my answer here for more details.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • @AL: When I clicked on grouped message not able to navigate to relevant screen even when expand and click on single message then able to navigate to that screen. Kindly suggest – Ajit Kumar Dubey Aug 31 '17 at 05:56
0

You are probably talking about InboxStyle notifications. You can make it like:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.notification_icon)
    .setContentTitle("Event tracker")
    .setContentText("Events received")
NotificationCompat.InboxStyle inboxStyle =
        new NotificationCompat.InboxStyle();
String[] events = new String[6];
// Sets a title for the Inbox in expanded layout
inboxStyle.setBigContentTitle("Event tracker details:");
...
// Moves events into the expanded layout
for (int i=0; i < events.length; i++) {

    inboxStyle.addLine(events[i]);
}
// Moves the expanded layout object into the notification object.
mBuilder.setStyle(inBoxStyle);
...
// Issue the notification here.
mNotificationManager.notify(mId, mBuilder.build());

Refer here for more details: InboxStyle Notifications

Kamran Ahmed
  • 7,661
  • 4
  • 30
  • 55