Android: Notificaciones agrupadas y resumen todavía se muestran por separado en 4.4 y abajo


Quiero implementar notificaciones apiladas en Android Wear Para hacerlo, creo 1 notificación de resumen y N notificaciones individuales para cada "elemento". Quiero que sólo se muestre el resumen en el teléfono. Aquí está mi código:

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

Esto funciona bien en Android 5.1, solo se muestra el resumen en la barra de notificaciones del teléfono:

introduzca la descripción de la imagen aquí

Pero en Android 4.4 también muestra notificaciones individuales 1 y 2:

introduzca la descripción de la imagen aquí

En ambos casos las notificaciones en Android Wear se muestran en una pila, según se desee. ¿Cómo hago que Android 4.4 solo muestre la notificación de resumen en la barra de notificaciones?

Author: Anton Cherkashyn, 2015-07-17

1 answers

Arreglado esto usando

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

En lugar de

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

Y reemplazando NotificationManager con NotificationManagerCompat en las firmas de método correspondientes.

 17
Author: Anton Cherkashyn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-21 18:57:38