【发布时间】:2015-11-09 11:15:45
【问题描述】:
我向用户发送多个通知,并使用不同的通知 ID 来创建和通知它们,并且所有通知只显示一个图标。一切都很完美。但是,当我滑动状态栏以查看通知时,它会显示单独的通知。
正如您在图片中看到的,我有两个单独的通知,而我喜欢像电报一样显示它们(2 条新消息)。 Android 是否有此功能,或者我必须使用检查以前通知的消息并计算未读通知并将其显示为 ContentText。
这是我的代码:
private final String GROUP_HEALTH = "HEALTH";
Random random = new Random();
int randInt = random.nextInt(9999 - 1000) + 1000;
int mNotificationId = randInt;
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
mContext, 0,intent,
PendingIntent.FLAG_CANCEL_CURRENT
);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext);
mBuilder.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_launcher)
.setTicker(mContext.getString(R.string.app_name))
.setContentTitle(title)
.setContentText(message)
.setContentIntent(resultPendingIntent)
.setGroup(GROUP_HEALTH)
.setContentInfo(notifType);
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(mNotificationId, mBuilder.build());
【问题讨论】:
-
感谢您的链接。我添加了
.setGroup(GROUP_HEALTH),但没有任何区别,我仍然收到分开的消息!!!另外为了显示消息计数和摘要,我应该自己计算和总结。 -
您能用您所做的更改更新您的代码吗?
标签: android notifications