setgroup() in notification not working

前端 未结 2 1129
Happy的楠姐
Happy的楠姐 2020-12-06 05:09

I\'m tring to create notification group, this is my code:

 // Build the notification, setting the group appropriately
 Notification notif = new NotificationC         


        
2条回答
  •  攒了一身酷
    2020-12-06 05:52

    You have to create a group notification before creating your custom notification. Just like this:

    NotificationCompat.Builder groupBuilder =
                new NotificationCompat.Builder(context)
                        .setContentTitle(title)
                        .setContentText(content)
                        .setGroupSummary(true)
                        .setGroup("GROUP_1")
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(content))
                        .setContentIntent(pendingIntent);
    

    Do not forget setGroupSummary to true.

    Then create your child notification which group value is same to groupBuilder's value。Here is "GROUP_1".

    NotificationCompat.Builder builder =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.ic_stat_communication_invert_colors_on)
                        .setContentTitle(title)
                        .setContentText(content)
                        .setGroup("GROUP_1")
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(content))
                        .setContentIntent(pendingIntent)
    

    Finally use NoticationManagerCompat to notify them.

        NotificationManagerCompat manager = NotificationManagerCompat.from(context);
        manager.notify(GROUP_ID, groupBuilder.build());
        manager.notify(id, builder.build());
    

提交回复
热议问题