Android – NotificationCompat.Builder que apila las notificaciones con setGroup (grupo) que no funciona

Quiero apilar notificaciones usando setGroup (como se describe aquí: https://developer.android.com/training/wearables/notifications/stacks.html ) Básicamente, uso 0 como id de notificación (siempre el mismo) y builder.setGroup("test_group_key") pero una nueva notificación siempre sustituye a la anterior. Cual podría ser el problema ?

Código:

 public BasicNotifier(Context context) { super(context); notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setSound(alarmSound) .setAutoCancel(true); stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(getParentActivityClass()); } public void showNotification(String title, String text, Intent intent, Class cls) { if (text.length() > 190) text = text.substring(0, 189) + "..."; mBuilder.setTicker(text).setContentText(text).setContentTitle(title); Intent notificationIntent = intent == null ? new Intent() : new Intent(intent); notificationIntent.setClass(getContext(), cls); stackBuilder.addNextIntent(notificationIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setGroup("test_group_key"); Notification notif = mBuilder.build(); notif.flags |= Notification.FLAG_AUTO_CANCEL; notifManager.notify(replaceOnNew ? 0 : nextId++, notif); // replaceOnNew // is "true" Log.i(TAG, "Notification shown: " + nextId + " = " + title); } 

EDITAR:

Parece que hay un problema al usar NotificationManagerCompat, las notificaciones no se muestran en absoluto.

  NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getContext()); notificationManager.notify(id, notif); 

No utiliza id de notificación correctamente.

"Para configurar una notificación para que pueda actualizarse, envíela con un ID de notificación llamando a NotificationManager.notify (ID, notificación) Para actualizar esta notificación una vez que la haya emitido, actualice o cree un objeto NotificationCompat.Builder, cree Un objeto de notificación de él, y emitir la notificación con el mismo ID que utilizó anteriormente. "

De Android Developer

Por lo tanto, en su caso, si desea apilar la notificación en su grupo, debe especificar un nuevo ID para cada nueva notificación.

  • Tamaño de MediaStyle LargeIcon
  • Cómo deshabilitar el botón Inicio sin utilizar TYPE_KEYGUARD?
  • Java.lang.NullPointerException: Intenta invocar el método de interfaz 'java.util.Iterator java.lang.Iterable.iterator ()' al iniciar una notación
  • ¿Cómo expandir la notificación de InboxStyle con sólo una línea añadida?
  • ¿Cómo crear una notificación sin icono en la barra de estado o simplemente ocultarlo?
  • ¿Es seguro utilizar Intent.FLAG_ACTIVITY_MULTIPLE_TASK?
  • Android: actualización de la barra de progreso de la notificación, correctamente
  • Cómo corregir: android.app.RemoteServiceException: Notificación incorrecta enviada desde el paquete *: No se pudo crear el icono: StatusBarIcon
  • INSTALL_FAILED_DUPLICATE_PERMISSION ... C2D_MESSAGE
  • Cómo solucionar este error: "android.app.RemoteServiceException: Mala notificación enviada desde el paquete"
  • ¿Cómo saber si la función Mostrar notificación está inhabilitada para mi aplicación?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.