Android在单个通知中显示多条消息

Android在单个通知中显示多条消息

问题描述:

当前,我收到来自服务器的通知。会发生什么,如果我收到通知,我很久没看到它。当一个新的通知来了,我失去了前一个。我想多封邮件是这样一个通知 -Android在单个通知中显示多条消息

enter image description here

这是InboxStyle通知

Notification notif = new Notification.Builder(mContext) 
.setContentTitle("5 New mails from " + sender.toString()) 
.setContentText(subject) 
.setSmallIcon(R.drawable.new_mail) 
.setLargeIcon(aBitmap) 
.setStyle(new Notification.InboxStyle() 
    .addLine(str1) 
    .addLine(str2) 
    .setContentTitle("") 
    .setSummaryText("+3 more")) 
.build(); 

Here是正式文件

检查这个例子也 - Inbox Style Notification Like Whatsapp

+0

谢谢你:)但在这里你有.addLine预定义的消息。我怎样才能动态地做到这一点。假设我收到100条消息,并且应该有100条addLine语句? – Mark023

+0

您需要将这些保存在本地数据库或首选项中,具体取决于您的应用程序。 –

+0

,你不能有100个添加行,因为你不能有这么多的通知,只需添加5-6行,而不是使用'summaryText' –