Tengo una app que implementa Cloud Functions y cuando un usuario manda un mensaje se activa una función que le manda al usuario que recibe el mensaje una notificación. Mi problema consiste en que al mandar varios mensajes consecutivos sobrescribe la notificación en si:
Titulo de notificacion 1: Ada
Texto de la notificacion 1: Hola como estas
Texto de notificacion 2: Ada
Texto de la notificacion 2: Me recibes?
Para hacerme explicar mejor... En caso de que esos dos mensajes (aunque sean más el resultado es el mismo) sean mandados muestra la 1 notificación, y al activarse la función en el 2 mensaje lo que hace es que la notificación que tenia con el texto de notificación 1 se sobrescriba con el de la segunda.
Como puedo lograr que cuando una persona te escriba varios mensajes consecutivos se agrupen en una conversación estilo Whatsapp o Telegram??
Lo que he intentado:
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message data payload: " + remoteMessage.getNotification());
createMessageNotificationChanel();
String body = remoteMessage.getNotification().getBody();
Log.d(TAG, "Message: " + body);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.MESSAGE_CHANNEL_ID))
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(body)
.setColor(ContextCompat.getColor(this, R.color.colorPrimary))
.setSmallIcon(R.drawable.ic_chat)
.setGroup(getString(R.string.MESSAGE_CHANNEL_ID))
.setVibrate(new long[]{0, 1000, 500, 1000})
.setSubText("Nuevo mensaje")
.setStyle(new NotificationCompat.InboxStyle()
.addLine(body))
.setLargeIcon(getBitmapFromURL(remoteMessage.getNotification().getIcon()))
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)
.setGroupSummary(true)
.setContentIntent(intent);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
// notificationId is a unique int for each notification that you must define
notificationManager.notify(R.integer.NOTIFICATION_MESSAGE_CHANEL_ID, builder.build());
}
private void createMessageNotificationChanel() {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = getString(R.string.message_chanel);
String description = getString(R.string.message_channel_description);
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(getString(R.string.MESSAGE_CHANNEL_ID), name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);
Objects.requireNonNull(notificationManager).createNotificationChannel(channel);
}
}
Que necesito agregar o cambiar para lograr ese tipo de comportamiento??