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)
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.
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.
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.
You are looking for "Big View Style", like this:
Related documentation:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With