[英]Issuing multiple notifications Android
我正在嘗試發出多個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)是我的問題,我希望新通知使用不同的行。
現在,我將所有內容放在一行中。
這是我現在得到的:
嘗試這個
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
嘗試這種方式:
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();
也可以去官方文檔獲取更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.