I don´t know how to group two or more notifications into only one and show a message like "You have two new messages".
Starting in Android 7.0 (API level 24), you can choose to display related notifications in a group (previously called "bundled" notifications). For example, if your app shows notifications for received emails, you should put all notifications into the same group so they can be collapsed together.
To create a stack, call setGroup() for each notification you want in the stack and specify a group key. Then call notify() to send it to the wearable. final static String GROUP_KEY_EMAILS = "group_key_emails"; // Build the notification, setting the group appropriately Notification notif = new NotificationCompat.
Android Notification Grouping Simply enter any value in the “Group Key” field under the Android Options when Sending Push Messages. This is the android_group parameter on the REST API. Notifications with the same group key will automatically group on the device.
Steps to be taken care from the below code.
NotificationCompat.Builder:contains the UI specification and action information NotificationCompat.Builder.build() :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() == R.id.btnCreateNotify){ NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle("Lanes"); builder.setContentText("Notification from Lanes"+value); builder.setSmallIcon(R.drawable.ic_launcher); builder.setLargeIcon(bitmap); builder.setAutoCancel(true); inboxStyle.setBigContentTitle("Enter Content Text"); inboxStyle.addLine("hi events "+value); builder.setStyle(inboxStyle); nManager.notify("App Name",NOTIFICATION_ID,builder.build()); } }
For separate notifications assign different NOTIFICATION_IDs..
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