Подтвердить что ты не робот

Android: сгруппированные уведомления и резюме все еще показаны отдельно на 4.4 и ниже

Я хочу реализовать сложенные уведомления на Android Wear. Для этого я создаю 1 сводное уведомление и N отдельных уведомлений для каждого "элемента". Я хочу, чтобы на телефоне показывалось только резюме. Здесь мой код:

private void showNotifications() {
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    showNotification1(notificationManager);
    showNotification2(notificationManager);
    showGroupSummaryNotification(notificationManager);
}

private void showNotification1(NotificationManager notificationManager) {
    showSingleNotification(notificationManager, "title 1", "message 1", 1);
}

private void showNotification2(NotificationManager notificationManager) {
    showSingleNotification(notificationManager, "title 2", "message 2", 2);
}

protected void showSingleNotification(NotificationManager notificationManager,
                                      String title,
                                      String message,
                                      int notificationId) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle(title)
            .setContentText(message)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setGroupSummary(false)
            .setGroup("group");
    Notification notification = builder.build();
    notificationManager.notify(notificationId, notification);
}

private void showGroupSummaryNotification(NotificationManager notificationManager) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle("Dummy content title")
            .setContentText("Dummy content text")
            .setStyle(new NotificationCompat.InboxStyle()
                    .addLine("Line 1")
                    .addLine("Line 2")
                    .setSummaryText("Inbox summary text")
                    .setBigContentTitle("Big content title"))
            .setNumber(2)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setCategory(Notification.CATEGORY_EVENT)
            .setGroupSummary(true)
            .setGroup("group");
    Notification notification = builder.build();
    notificationManager.notify(123456, notification);
}

Это отлично работает на Android 5.1, только сводка отображается на панели уведомлений телефона:

enter image description here

Но на Android 4.4 он также показывает отдельные уведомления 1 и 2:

enter image description here

В обоих случаях уведомления на Android Wear отображаются в стеке, если требуется. Как заставить Android 4.4 показывать сводное уведомление на панели уведомлений?

4b9b3361

Ответ 1

Исправлено это с помощью

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

вместо

NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

и заменяет NotificationManager NotificationManagerCompat в соответствующих сигнатурах методов.

Ответ 2

Вы просто showSingleNotification метод showSingleNotification и замените

notificationManager.notify(123456, notification); 

с

notificationManager.notify(123456, builder); 

и его работа в порядке.