【问题标题】:To receive multiple push notifications of different criteria and update the notification based on that接收不同标准的多个推送通知并根据该标准更新通知
【发布时间】:2015-11-18 13:24:21
【问题描述】:

我已合并 GCM 通知,但它会覆盖现有的,然后通过

中给出的建议

this link我用了得到了,但是更新为多条通知,需要像这张图那样实现-

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

在最起码的情况下,我试图从 3 个聊天中获得 5 条消息作为总结通知,有什么解决方法吗?

【问题讨论】:

  • 扩展摘要布局或收件箱样式代码 sn-p 将非常有用。

标签: android notifications push-notification google-cloud-messaging


【解决方案1】:

我得到了答案,尝试了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());
}

`

【讨论】:

    【解决方案2】:

    我终于定制了它,通过这段代码来实现它。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-24
      • 1970-01-01
      • 1970-01-01
      • 2019-04-23
      • 1970-01-01
      • 2017-10-24
      • 1970-01-01
      • 2023-03-06
      相关资源
      最近更新 更多