我正在尝试发出多个notifications
(在发出一个通知后,我想加上这个)。
我已经阅读了官方文档,其中描述了通知编号应该是唯一的,应该用于更新通知。但是我发现很难为新的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()执行附加更多文本所需的技巧,但是我没有获得新行?有任何想法吗?
行(M.Twain)对我来说是一个问题,我想要新的通知不同的行。
现在我把所有东西都放在一行。
以下是我现在的意见:
答案 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
答案 1 :(得分: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了解更多信息。