0

I send couple notifications to the user and I use different notification ID for creating and notifying them and only one icon appears for all notifications. Everything is perfect. However when I swipe status bar to see notifications, it shows separated notifications.

enter image description here

As you see in the image I have two separated notifications, while I like to show them like telegram does (2 new messages). Does Android have something for that or I have to use a check previous notified messages and count unread notifications and show it as ContentText.

This is my code:

private final String GROUP_HEALTH = "HEALTH";

    Random random = new Random();
    int randInt = random.nextInt(9999 - 1000) + 1000;
    int mNotificationId = randInt;

    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                    mContext, 0,intent,
                    PendingIntent.FLAG_CANCEL_CURRENT
            );

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext);

    mBuilder.setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setWhen(System.currentTimeMillis())
            .setSmallIcon(R.drawable.ic_launcher)
            .setTicker(mContext.getString(R.string.app_name))
            .setContentTitle(title)
            .setContentText(message)
            .setContentIntent(resultPendingIntent)
            .setGroup(GROUP_HEALTH)
            .setContentInfo(notifType);

    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(mNotificationId, mBuilder.build());
Taher
  • 1,185
  • 3
  • 18
  • 36
  • 1
    please refer to this [link](http://developer.android.com/training/wearables/notifications/stacks.html) or refer this question [link](http://stackoverflow.com/questions/20748049/android-multiple-line-notification-like-gmail-app) – Yograj Shinde Nov 09 '15 at 11:21
  • Thanks for link. I added `.setGroup(GROUP_HEALTH)` but it didn't make any difference, I still get separated messages!!! Also for showing message count and summery, I should count and summerize by myself. – Taher Nov 09 '15 at 12:02
  • can you please update your code with changes you have done? – Yograj Shinde Nov 09 '15 at 12:06

1 Answers1

0

i guess every time this code runs, it generates random ID for every notification, use constant ID.

    int mNotificationId = 1;

And yes, you should check for unread messages, and show that count by yourself.

xdigit
  • 111
  • 4
  • When I use same ID for all notifications, if there is an unseen notification, the system will not notify new one, however the old one will replace with the new one. – Taher Nov 09 '15 at 12:21