2014-02-12 56 views
0

我想发出多个notifications(发出一个通知后,我想加上)。发出多个通知Android

我已经通过了官方文档,其中描述了通知编号应该是唯一的,并且应该用于更新通知。不过,我发现很难为新的notification(inboxStyle)添加一条新线。下面是我的代码:

public void notificationFetch(int number, String greeting, String header){ 


     NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); 
     inboxStyle.addLine(Html.fromHtml("<i>italic</i> <b>bold</b>")); 



     NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setUsesChronometer(true).setTicker("tickerText").setStyle(inboxStyle) 
       .setLights(Color.BLUE, 200, 300).setSmallIcon(R.drawable.ic_launcher) 
       .setContentTitle("Reminder").setContentText(header).setSubText(greeting).setNumber(number); 





     Intent resultIntent = new Intent(this, MainActivity.class); 
     TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 
     stackBuilder.addParentStack(MainActivity.class); 
     stackBuilder.addNextIntent(resultIntent); 
     PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); 
     mBuilder.setContentIntent(resultPendingIntent); 
     NotificationManager mNotificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE); 
     mNotificationManager.notify(number, mBuilder.build()); 

    } 

.setSubText()不追加更多的文本中所需的技巧,但我没有得到新的生产线?有任何想法吗?

Example Image:

的行(M.Twain)是一个问题的问题与我,我要为新的通知不同的线路。

现在我把所有东西都放在一行中。

这里是我所得到的现在:

enter image description here

+1

我没有得到你,你究竟想要什么 –

+0

请检查编辑的问题。 – User3

+0

上传一个快照。 –

回答

0

试试这个

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

这里是样本链接

http://developer.android.com/reference/android/app/Notification.InboxStyle.html

0

试试这个方法:

Notification notification = new Notification.InboxStyle(new Notification.Builder(context) 
.setTicker(message) 
.setSmallIcon(icon) 
.setWhen(when) 
.setContentTitle(title) 
.setContentText(subTitle) 
.setNumber(4) 
.setContentIntent(intent)) 
.addLine("First Message") 
.addLine("Second Message") 
.addLine("Third Message") 
.addLine("Fourth Message") 
.setBigContentTitle("Here Your Messages") 
.setSummaryText("+3 more") 
.build(); 

也请到官方docs了解更多信息。

+0

查找等待意图的问题。你能给我一个工作的例子吗? – User3

+0

@ user2822178首先更新您的完整代码 –

+0

请检查更新后的问题。 – User3