Android 接收不同条件的多个推送通知并基于该条件更新通知

Android 接收不同条件的多个推送通知并基于该条件更新通知,android,notifications,push-notification,google-cloud-messaging,Android,Notifications,Push Notification,Google Cloud Messaging,我已经加入了GCM通知,但它覆盖了现有通知,然后根据中给出的建议 我使用并获得了它,但它正在更新为多个通知,需要实现如下图像- 在这里,我无法在多行中实现这种类型。我正在尝试使用而不是使用样式和展开,但我需要按照中声明的方式堆叠通知 至少在这种情况下,我试图从3次聊天中获得5条消息,作为通知的总结,这方面有什么解决办法吗?我得到了答案,尝试了如下 ` `我得到了答案,试着 ` `我最终定制了它,并通过这段代码实现了它 int notificationId = Prefs.getIntPref(

我已经加入了GCM通知,但它覆盖了现有通知,然后根据中给出的建议

我使用并获得了它,但它正在更新为多个通知,需要实现如下图像-

在这里,我无法在多行中实现这种类型。我正在尝试使用而不是使用样式和展开,但我需要按照中声明的方式堆叠通知


至少在这种情况下,我试图从3次聊天中获得5条消息,作为通知的总结,这方面有什么解决办法吗?

我得到了答案,尝试了如下

`


`我得到了答案,试着

`


`

我最终定制了它,并通过这段代码实现了它

int notificationId =  Prefs.getIntPref(context, Prefs.NEWLEAD_NOTIFY, 0);
        Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.putExtra("message",message);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(MainActivity.class);
        stackBuilder.addNextIntent(notificationIntent);

        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_CANCEL_CURRENT);


        Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.logo);
        array_messages.add(message);

        NotificationCompat.Builder builder =  new NotificationCompat.Builder(context)
                .setTicker("My product")
                .setSmallIcon(icon)
                .setLargeIcon(largeIcon)
                .setWhen(System.currentTimeMillis())
                .setContentTitle("My product")
                .setContentIntent(resultPendingIntent)
        .setAutoCancel(true).setDefaults(Notification.FLAG_AUTO_CANCEL).setDefaults(Notification.DEFAULT_SOUND)
                .setDefaults(Notification.DEFAULT_VIBRATE) ;

        if(array_messages.size()==1)
            builder.setContentText(message);
        else
            builder.setContentText(array_messages.size() +" Lead notifications");


        NotificationCompat.InboxStyle inboxStyle =
                new NotificationCompat.InboxStyle();
        if(array_messages.size()<=5) {
            for (int i = 0; i < array_messages.size(); i++) {

                inboxStyle.addLine(array_messages.get(i));
            }
            inboxStyle.setBigContentTitle("My Product");
            inboxStyle.setSummaryText(array_messages.size() +" Lead notifications");
        }
        else {
            for (int i = 0; i <= 5; i++) {

                inboxStyle.addLine(array_messages.get(i));
            }

            inboxStyle.setBigContentTitle("My product");
            inboxStyle.setSummaryText(array_messages.size() +" Lead notifications");
        }
        builder.setStyle(inboxStyle);

        notificationManager.notify(0, builder.build());

        notificationId = notificationId + 1;

        Prefs.setIntPref(context, Prefs.NEWLEAD_NOTIFY, notificationId);

我最终定制了它,以通过这段代码实现它

int notificationId =  Prefs.getIntPref(context, Prefs.NEWLEAD_NOTIFY, 0);
        Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.putExtra("message",message);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(MainActivity.class);
        stackBuilder.addNextIntent(notificationIntent);

        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_CANCEL_CURRENT);


        Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.logo);
        array_messages.add(message);

        NotificationCompat.Builder builder =  new NotificationCompat.Builder(context)
                .setTicker("My product")
                .setSmallIcon(icon)
                .setLargeIcon(largeIcon)
                .setWhen(System.currentTimeMillis())
                .setContentTitle("My product")
                .setContentIntent(resultPendingIntent)
        .setAutoCancel(true).setDefaults(Notification.FLAG_AUTO_CANCEL).setDefaults(Notification.DEFAULT_SOUND)
                .setDefaults(Notification.DEFAULT_VIBRATE) ;

        if(array_messages.size()==1)
            builder.setContentText(message);
        else
            builder.setContentText(array_messages.size() +" Lead notifications");


        NotificationCompat.InboxStyle inboxStyle =
                new NotificationCompat.InboxStyle();
        if(array_messages.size()<=5) {
            for (int i = 0; i < array_messages.size(); i++) {

                inboxStyle.addLine(array_messages.get(i));
            }
            inboxStyle.setBigContentTitle("My Product");
            inboxStyle.setSummaryText(array_messages.size() +" Lead notifications");
        }
        else {
            for (int i = 0; i <= 5; i++) {

                inboxStyle.addLine(array_messages.get(i));
            }

            inboxStyle.setBigContentTitle("My product");
            inboxStyle.setSummaryText(array_messages.size() +" Lead notifications");
        }
        builder.setStyle(inboxStyle);

        notificationManager.notify(0, builder.build());

        notificationId = notificationId + 1;

        Prefs.setIntPref(context, Prefs.NEWLEAD_NOTIFY, notificationId);

扩展摘要布局或inboxStyle代码段将非常有用。扩展摘要布局或inboxStyle代码段将非常有用。