2017-01-17 6 views
1

Я хочу показать уведомления, например, на картинке. Если есть более одного, я хочу показать счетчик тоже. Я не нашел информацию в официальном документе. Теперь я просто обновить уведомление по идентификатору:Уведомления группы на Android

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

notification example

Как я могу это сделать?

ответ

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()); 
+0

Thanx, попробуем позже) –

+0

Это работает, если нужно, thanx) –

+1

Что такое 'mNumber '? – testing

0

Чтобы создать стек, вызовите setGroup() для каждого уведомления, которое вы хотите в стеке, и укажите групповой ключ.

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); 

Ссылка:. https://developer.android.com/training/wearables/notifications/stacks.html

+0

Thanx, будет проверять позже сегодня) –

+0

@RuslanPodurets сделал эту помощь? –

+1

не было. (Уведомление просто обновляется, как в моем коде ( –