How to display multiple notification as a group?

后端 未结 4 1964
面向向阳花
面向向阳花 2021-02-20 11:01

here is my code for notification. it generate a new notification each time

Random random = new Random();
int m = random.nextInt(9999 - 1000);    
Notific         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-20 11:43

    It will generate notification with multiple messages like Gmail

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.quemark1)
                        .setContentTitle("Title")
                        .setContentText("New Message received");
                NotificationCompat.InboxStyle inboxStyle =
                        new NotificationCompat.InboxStyle();
    
                inboxStyle.setBigContentTitle("doUdo");
    
               // Add your All messages here or use Loop to generate messages
    
                    inboxStyle.addLine("Messgare 1");
                    inboxStyle.addLine("Messgare 2");
                              .
                              .
                    inboxStyle.addLine("Messgare n");
    
    
                mBuilder.setStyle(inboxStyle);
                TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    
                stackBuilder.addNextIntent(intent);
    
                PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
    
                mBuilder.setContentIntent(pIntent);
    
                NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                mBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
                mBuilder.setAutoCancel(true);
                mNotificationManager.notify(0, mBuilder.build());
    

提交回复
热议问题