This push notification is used to notify when a new chat message is available. I want to do like Instagram, that is to say, the message into this notification is updated at each new income message received, until the user open the chat.
So, how can I retrieve the message for this specific notification? Is it possible, or I have to save (in cache) the latest messages... ?
Thank you very much
CodePudding user response:
I suggest saving messages in the database, and then in the function that sends notifications, get messages (probably recent unread ones - I don't know what your logic looks like in this case). If there are more than one, use InboxStyle():
val otherMessagesToShow = getMostRecentUnreadMessages()
if(otherMessagesToShow.size > 1) {
val style = NotificationCompat.InboxStyle()
otherMessagesToShow.forEach { style.addLine(it) }
builder.setStyle(style)
builder.setNumber(otherMessagesToShow.size)
}
Finally, update the existing one (passing the same notificationID):
notificationManager.notify(notificationId, builder.build())