2

I want to show notifications like on picture. If there is more than one, I want to show a counter too. I didn't find info in official doc. Now I just update my notification by id:

((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
                .notify(PUSH_NOTIFICATION_ID, notification);

notification example

How can I do it ?

megaturbo
  • 680
  • 6
  • 24
Ruslan Podurets
  • 151
  • 1
  • 2
  • 9

2 Answers2

2
NotificationCompat.Builder mBuilder = new  NotificationCompat.Builder(getApplicationContext());
            mBuilder.setSmallIcon(R.mipmap.ic_launcher);
            mBuilder.setContentTitle(topic);
            mBuilder.setContentText(new String(message.getPayload()));
            mBuilder.setAutoCancel(true);
            mBuilder.mNumber = 1;//get your number of notification from where you have save notification

            NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            mNotifyMgr.notify(notify_id, mBuilder.build());
D.J
  • 1,439
  • 1
  • 12
  • 23
1

To create a stack, call setGroup() for each notification you want in the stack and specify a group key.

final static String GROUP_KEY_EMAILS = "group_key_emails";

    // Build the notification, setting the group appropriately
    Notification notif = new NotificationCompat.Builder(mContext)
             .setContentTitle("New mail from " + sender1)
             .setContentText(subject1)
             .setSmallIcon(R.drawable.new_mail)
             .setGroup(GROUP_KEY_EMAILS)
             .build();

    // Issue the notification
    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(this);
    notificationManager.notify(notificationId1, notif);

Reference: https://developer.android.com/training/wearables/notifications/stacks.html

Amey Shirke
  • 599
  • 1
  • 5
  • 16