Android 合并多推送通知

Android 合并多推送通知,android,push-notification,Android,Push Notification,如何将多个通知合并为一个通知?我可以收到每封邮件的通知,但我只需要一封。请建议 下面是我的代码: private void sendNotification(String id, String title, String messageBody, Map<String, String> data, boolean showNotification) { Bundle bundle = new Bundle(); for (String key : data.ke

如何将多个通知合并为一个通知?我可以收到每封邮件的通知,但我只需要一封。请建议

下面是我的代码:

  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);
    }
}
private void sendNotification(字符串id、字符串标题、字符串消息体、映射数据、布尔showNotification){
Bundle=新Bundle();
for(字符串键:data.keySet()){
bundle.putString(key,data.get(key));
}
如果(显示通知){
Intent Intent=新的Intent(这是OnNotificationOpenReceiver.class);
意向。额外支出(捆绑);
PendingEvent PendingEvent=PendingEvent.getBroadcast(这个,id.hashCode(),intent,
PendingEvent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_通知);
NotificationCompat.Builder notificationBuilder=新建NotificationCompat.Builder(此)
.setContentTitle(标题)
.setContentText(messageBody)
.setStyle(新的NotificationCompat.BigTextStyle().bigText(messageBody))
.setAutoCancel(真)
.setSound(defaultSoundUri)
.setContentIntent(挂起内容);
int resID=getResources().getIdentifier(“通知图标”,“可绘制”,getPackageName());
如果(剩余=0){
notificationBuilder.setSmallIcon(剩余);
}否则{
notificationBuilder.setSmallIcon(getApplicationInfo().icon);
}
通知经理通知经理=
(NotificationManager)getSystemService(上下文通知服务);
notificationManager.notify(id.hashCode(),notificationBuilder.build());
}否则{
bundle.putBoolean(“tap”,false);
FirebasePlugin.sendNotification(捆绑包);
}
}

将通知数据存储在数据库中,取消当前未勾选的通知,并尝试将捆绑通知一起显示。谢谢你,卡马尔。我是一名C#开发人员,不知道如何使用Java。这段代码来自一个名为cordovcm的插件。请建议,即使对于多个通知,如何将id.hashcode()保留为默认值。