0

I am creating a Chat Application with Firebase. I send Notifications with Firebase Cloud Functions and recieve them on my phone. But for every message I get a new notification. And now I want to know if it is possible to create a Notification like in WhatsApp, with multible lines for each message in one Notification. My Code for a Notification:

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    String notification_tag = remoteMessage.getData().get("senderUiD");

        Intent intent = new Intent(getApplicationContext(), Chat_Room.class);

        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(remoteMessage.getData().get("username"))
                .setContentText(remoteMessage.getNotification().getBody())
                .setVibrate(new long[]{1500, 0, 1500, 0})
                .setLights(Color.BLUE, 2000, 1000)
                .setWhen(remoteMessage.getSentTime())
                .setAutoCancel(true)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(remoteMessage.getNotification().getBody()))
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                .setContentIntent(pendingIntent);

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

Thanks for your help ;)

KENdi
  • 7,576
  • 2
  • 16
  • 31
Karl Wolf
  • 268
  • 2
  • 13
  • I strongly recomend you to read this links: https://stackoverflow.com/questions/33040737/how-to-group-android-notifications-like-whatsapp https://stackoverflow.com/questions/41692501/group-notifications-on-android – Rodrigo Gontijo Jul 27 '17 at 18:31

1 Answers1

0

When You Are Receiving Notification Message Your Notification In override last Notification

generate Rendam number

Random ran = new Random();
int notification_tag = r`an.nextInt(6) + 5;`

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

also, fallow few step for grouping notification

NotificationCompat.Builder:contains the UI specification and action information
NotificationCompat.Builder.build() :used to create notification (Which returns Notification object)
Notification.InboxStyle: used to group the notifications belongs to same ID
NotificationManager.notify():to issue the notification.
Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28