Android Question

How to group android notifications like whatsapp?

I donĀ“t know how to group two or more notifications into only one and show a message like "You have two new messages".

Answer Source

Steps to be taken care from the below code.

NotificationCompat.Builder:contains the UI specification and action information :used to create notification (Which returns Notification object)
Notification.InboxStyle: used to group the notifications belongs to same ID
NotificationManager.notify():to issue the notification.

Use the below code to create notification and group it. Include the function in a button click.

private final int NOTIFICATION_ID = 237;
private static int value = 0;
Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.push_notify_icon);
public void buttonClicked(View v)
        value ++;
        if(v.getId() =={
            NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            Notification.Builder builder = new Notification.Builder(this);            
            builder.setContentText("Notification from Lanes"+value);
            inboxStyle.setBigContentTitle("Enter Content Text");
            inboxStyle.addLine("hi events "+value);
            nManager.notify("App Name",NOTIFICATION_ID ,;

For separate notifications assign different NOTIFICATION_IDs..