I want to build grouped notifications on Android that work like popular email clients where multiple messages appear stacked under a single notification header.
Currently I can only make individual notifications using this approach:
public void buildSimpleNotification(String headerText, String bodyContent, String displayText) {
int iconResource = R.drawable.app_notification_icon;
CharSequence tickerDisplay = displayText;
long timestamp = System.currentTimeMillis();
Context appContext = getApplicationContext();
CharSequence notificationHeader = headerText;
CharSequence notificationBody = bodyContent;
Intent launchIntent = new Intent(this, HomeActivity.class);
Bundle extras = new Bundle();
extras.putString("header", headerText);
extras.putString("content", bodyContent);
launchIntent.putExtras(extras);
PendingIntent actionIntent = PendingIntent.getActivity(this, 0,
launchIntent, PendingIntent.FLAG_ONE_SHOT
+ PendingIntent.FLAG_UPDATE_CURRENT);
String serviceType = Context.NOTIFICATION_SERVICE;
NotificationManager notificationService = (NotificationManager) getSystemService(serviceType);
Notification singleNotification = new Notification(iconResource, tickerDisplay, timestamp);
singleNotification.setLatestEventInfo(appContext, notificationHeader, notificationBody, actionIntent);
singleNotification.defaults |= Notification.DEFAULT_LIGHTS;
singleNotification.defaults |= Notification.DEFAULT_SOUND;
singleNotification.defaults |= Notification.FLAG_AUTO_CANCEL;
singleNotification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
final int NOTIFICATION_ID = 0;
notificationService.notify(NOTIFICATION_ID, singleNotification);
}
How can I create a notification group where I can stack multiple notification items together instead of showing them separately?