我的问题通过以下链接解决:
这是我的代码:
PendingIntent pendingIntent = PendingIntent.getBroadcast(objContext, (int) (Math.random() * 100), intent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationManager manager = (NotificationManager) objContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (firstTime) {
intCount++;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
inboxStyle = new Notification.InboxStyle();
}
Bitmap icon = BitmapFactory.decodeResource(objContext.getResources(), R.drawable.ic_launcher);
// Notification.Builder builder = new Notification.Builder(objContext);
builder = new Notification.Builder(objContext);
builder.setAutoCancel(true);
builder.setContentTitle("Studyboard");
builder.setDefaults(Notification.DEFAULT_ALL);
builder.setSmallIcon(R.drawable.ic_launcher_transparent_s);
builder.setLargeIcon(icon);
builder.setWhen(Calendar.getInstance().getTimeInMillis());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
builder.setStyle(inboxStyle);
}
builder.setOngoing(false);
builder.setContentIntent(pendingIntent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
builder.build();
inboxStyle.addLine(senderFullName + " : " + strDisplayMsg);
inboxStyle.setSummaryText("");
}
System.out.println("Creating New Notification");
Notification myNotication = builder.getNotification();
manager.notify("Example", 12345, myNotication);
firstTime = false;
} else {
intCount++;
builder.setWhen(Calendar.getInstance().getTimeInMillis());
System.out.println("Not Creating");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
builder.setStyle(inboxStyle);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (intCount <= 3)
inboxStyle.addLine(senderFullName + " : " + strDisplayMsg);
if (intCount > 3 && intCount - 3 > 0)
inboxStyle.setSummaryText("+" + (intCount - 3) + " more messages");
}
Notification myNotication = builder.getNotification();
manager.notify("Example", 12345, myNotication);
}
inboxStyle.addLine()
函数可以帮助你更新通知内容。 - Anil Ravsaheb GhodakeContentText("text text 1")
-> 按钮点击 -> ContentText("text text 2")
- Thorvald