Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android multiple line notification like Gmail app

I am trying to create a multiple line notification like the Gmail application does as shown in the image below (the 5 notifications grouped under one notification)

enter image description here

I have tried various examples but can only seem to create single notifications like

   public void createSingleNotification(String title, String messageText, String tickerttext) {         int icon = R.drawable.notification_icon; // icon from resources         CharSequence tickerText = tickerttext; // ticker-text         long when = System.currentTimeMillis(); // notification time         Context context = getApplicationContext(); // application Context         CharSequence contentTitle = title; // expanded message title         CharSequence contentText = messageText; // expanded message text         Intent notificationIntent = new Intent(this, MainActivity.class);          Bundle xtra = new Bundle();         xtra.putString("title", title);         xtra.putString("message", messageText);          notificationIntent.putExtras(xtra);         PendingIntent contentIntent = PendingIntent.getActivity(this, 0,           notificationIntent, PendingIntent.FLAG_ONE_SHOT             + PendingIntent.FLAG_UPDATE_CURRENT);         String ns = Context.NOTIFICATION_SERVICE;          NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);         Notification notification = new Notification(icon, tickerText, when);         notification.setLatestEventInfo(context, contentTitle, contentText,   contentIntent);         notification.defaults |= Notification.DEFAULT_LIGHTS;         notification.defaults |= Notification.DEFAULT_SOUND;         notification.defaults |= Notification.FLAG_AUTO_CANCEL;         notification.flags = Notification.DEFAULT_LIGHTS           | Notification.FLAG_AUTO_CANCEL;         final int HELLO_ID = 0;         mNotificationManager.notify(HELLO_ID, notification);       } 

I am not sure how to create a notification group that I can add lines to.

like image 828
user3013243 Avatar asked Dec 23 '13 17:12

user3013243


People also ask

How do I show multiple notifications on Android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


2 Answers

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)     .setSmallIcon(R.drawable.notification_icon)     .setContentTitle("Event tracker")     .setContentText("Events received") NotificationCompat.InboxStyle inboxStyle =         new NotificationCompat.InboxStyle();  String[] events = {"line 1","line 2","line 3","line 4","line 5","line 6"}; // Sets a title for the Inbox in expanded layout inboxStyle.setBigContentTitle("Event tracker details:"); ... // Moves events into the expanded layout for (int i=0; i < events.length; i++) {     inboxStyle.addLine(events[i]); } // Moves the expanded layout object into the notification object. mBuilder.setStyle(inboxStyle);  ... // Issue the notification here. 
like image 121
Ganesh Katikar Avatar answered Oct 08 '22 21:10

Ganesh Katikar


You are looking for "Big View Style", like this:

enter image description here

Related documentation:

  • Notifications
  • Using Big View Styles
like image 35
Marcin Orlowski Avatar answered Oct 08 '22 20:10

Marcin Orlowski