Setgroup () in notification does not work

I am trying to create a notification group, this is my code:

// Build the notification, setting the group appropriately Notification notif = new NotificationCompat.Builder(getApplicationContext()) .setContentTitle("New mail from " + 1) .setContentText("cv") .setSmallIcon(R.drawable.rh_logo) .setStyle(new NotificationCompat.InboxStyle() .addLine("Alex Faaborg Check this out") .addLine("Jeff Chang Launch Party") .setBigContentTitle("2 new messages") .setSummaryText(" johndoe@gmail.com ")) .setGroup(GROUP_KEY_EMAILS) .setGroupSummary(true) .build(); // Issue the notification NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(++NOTIFICATION_ID, notif); 

When I launch the application and send notifications, they do not appear in the group. Can someone explain to me what I need to change?

+3
android notifications
source share
2 answers

Before creating a custom notification, you must create a group notification. Similar:

 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 a child notification that the group value matches the value of groupBuilder . 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()); 
+9
source share

Replace

 NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(++NOTIFICATION_ID, notif); 

from

 NotificationManagerCompat.from(mCtx).notify(++NOTIFICATION_ID,notif); 

because you are using NotificationCompat

+1
source share

All Articles