如何将多个通知合并为一个?我能够获得每条消息的通知,但我只需要一条消息。请建议。
以下是我的代码:
private void sendNotification(String id, String title, String messageBody, Map<String, String> data, boolean showNotification) {
Bundle bundle = new Bundle();
for (String key : data.keySet()) {
bundle.putString(key, data.get(key));
}
if (showNotification) {
Intent intent = new Intent(this, OnNotificationOpenReceiver.class);
intent.putExtras(bundle);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, id.hashCode(), intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(messageBody)
.setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
int resID = getResources().getIdentifier("notification_icon", "drawable", getPackageName());
if (resID != 0) {
notificationBuilder.setSmallIcon(resID);
} else {
notificationBuilder.setSmallIcon(getApplicationInfo().icon);
}
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id.hashCode(), notificationBuilder.build());
} else {
bundle.putBoolean("tap", false);
FirebasePlugin.sendNotification(bundle);
}
}