Inbox Style Notifications Such As Whatsapp

Android notifications will be displayed in the notification area and to see the details regarding the notification, the user can expand it by opening the notification drawer.
 
Note - Inbox style notification is not available on platforms prior to Android 4.1.

When you want to display multiline text detail sections, you can use NotificationCompat.InboxStyle.

  1. Notification notification = new Notification.InboxStyle(builder)  
  2.    .addLine()  
  3.    .setBigContentTitle()  
  4.    .setSummaryText()  
  5.    .build();  
Now we will see a step by step example of inbox style notification. First create the object of your intent, it will be targeted activity where the user will be redirected when clicking on the notification.
  1. Intent resultIntent = new Intent(context, ResuleActivity.class);  
  2. resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);  
  3. PendingIntent piResult = PendingIntent.getActivity(this0, resultIntent, 0);  
Create an object of Notification.Builder. 
  1. Notification.Builder builder=new Notification.Builder(context)  
  2.    .setSmallIcon(R.mipmap.ic_launcher)  
  3.    .setContentTitle("contentTitle")  
  4.    .setContentText("contentText")  
  5.    .setContentIntent(piResult);  
contentTitle and contentText will be shown when your notification is not expanded. Now create an inbox style notification object. 
  1. Notification notification = new Notification.InboxStyle(builder)  
  2.    .addLine("First Message")  
  3.    .addLine("Second Message")  
  4.    .addLine("Third Message")  
  5.    .addLine("Fourth Message")  
  6.    .setBigContentTitle("Here Your Messages")  
  7.    .setSummaryText("+3 more")  
  8.    .build();  

Here you can give your messages in addLine(), while setSummaryText() will be used to show a summary of your notifications.

Now the final step is to showthe notification in the notification area.

  1. NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);  
  2. notificationManager.notify(121,notification);  
Here is what it looks like when you execute this code,