接收不同标准的多个推送通知并根据该标准更新通知

To receive multiple push notifications of different criteria and update the notification based on that

我已经合并了 GCM 通知,但它覆盖了现有的,然后根据

中给出的建议

this link 我用过并得到它,但它正在更新为多个通知,需要像这个图像一样实现 -

这里我无法在多行中实现这种类型。我正在尝试 BigNotify not with styles and expand but i need to stack the notification as declared in Summarize notification guide

至少我正在尝试从 3 次聊天中获得 5 条消息作为通知的总结,是否有解决此问题的方法?

我得到了答案,试过了 this

`

public static void pushNotification(Activity currentActivity, String title, String content[]){

    NotificationManager nm = (NotificationManager) currentActivity.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent resultIntent = new Intent(currentActivity.getBaseContext(), FileSharingActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(currentActivity);
    stackBuilder.addParentStack(FileSharingActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);


    nm.notify(nextId++, new Notification.InboxStyle(new Notification.Builder(currentActivity.getBaseContext())
            .setTicker("Ticker")
            .setSmallIcon(R.drawable.ic_launcher)
            .setWhen(System.currentTimeMillis())
            .setContentTitle("Content title")
            .setContentText("Content text")
            .setNumber(4)
            .setContentIntent(resultPendingIntent))
            .addLine("First Message")
            .addLine("Second Message")
            .addLine("Third Message")
            .addLine("Fourth Message")
            .setBigContentTitle("Here Your Messages")
            .setSummaryText("+3 more")
            .build());
}

`

我终于通过这段代码自定义实现了。

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);