Reputation: 12454
When multiple mails arrive one by one, Gmail groups them and shows only one notification message on the Notification Area. I would like to do the same thing. I searched Google and found that I need to set tag
, but setting the same tag
just replaced the previous one, not showing multiple messages as Gmail.
Should I not use the notification-type, but use the data-type only and handle notifications myself? If so, this should be something a lot of people are ding. Is there a sample project that I can start with?
Also, if I can somehow use the notification-type for grouping, it gives the data as Intent extras. How does it pass multiple data to my activity, if the notification is showing multiple items as Gmail?
{
"to": "/topics/that",
"notification": {
"title": "Title 686",
"body": "My body",
"tag": "xxx"
},
"data": {
"title": "Title 686",
"body": "My body",
}
}
Upvotes: 1
Views: 1150
Reputation: 635
You can use inbox style with notification builder
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_glyph)
.setContentTitle(title)
.setColor(context.getResources().getColor(R.color.colorPrimary))
.setContentText(contentText);
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
for (int i = 1; i < 11; i++) {
inboxStyle.addLine(("Message " + i);
}
inboxStyle.setBigContentTitle(title);
mBuilder.setStyle(inboxStyle);
Upvotes: 1