Inbox Style Notification Like Whatsapp

In this post we will discuss about Inbox style notification like Whatsapp, Gmail and other chat applications are having.

Android notification will be displayed in Notification area and to see the details regarding the notification, the user can expand it in by open 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 section, you can use NotificationCompat.InboxStyle.

Syntax:

Now we will see step by step example of Inbox style notification. First create object of your intent, it will be targeted activity where user will be redirected when click on notification.

Create an object of Notification.Builder.

contentTitle and contentText will be shown when your notification is not expanded. Now create Inbox style notification object.

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

Now final step is to show notification in notification area.

Here what it looks like when you execute this code :

Inbox Style Notification Like Whatsapp Inbox Style Notification Like Whatsapp

Part of TextView clickable
Android’s Runtime Permission

  • freddy pradeep

    Hi Ravi ! you showed the static way to add those lines . but how to add dynamic msgs . suppose there are 3 new msgs from 3 users in watsapp. how to do you show that ? with only one icon in status bar and the notifications stacked one above the other . how do u do that ???

    • Ravi

      You can manage unread messages in database and then while showing the notification fetch it from database and inside for loop you can place addLine(“your message from db”);
      Regarding messages from different users, you need to manage it by your own logic, there is nothing to do with how you are showing notification. Build your logic to check whether its from different user or not and than mention user name in addLine(userName + message)

  • Awesome.

    May you have to use NotificationCompat instead Notification class.