Empilar las notificaciones no funciona

Necesito formar un grupo de notificaciones. Hice el ejemplo de la descripción del enlace aquí

Pero mi aviso no está agrupado. ¿qué hice mal?

mi código:

private static int id =0; final static String GROUP_KEY_GUEST = "group_key_guest"; private static void generateNotification(Context context, String message) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); Intent intent = new Intent(context,MyActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new NotificationCompat.Builder(context) .setContentIntent(pendingIntent) .setSmallIcon(R.drawable.ic_stat_gcm) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_gcm)) .setTicker("New Message") .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setContentTitle("Message") .setContentText(message) .setGroup(GROUP_KEY_GUEST) .build(); notificationManager.notify(id++, notification); } 

Llamada al método:

  @Override protected void onMessage(Context context, Intent intent) { Log.d(TAG, "Поступило сообщение: " + intent.getExtras()); String message = intent.getStringExtra("content"); generateNotification(context, message); } 

EDIT, código completo: Este es mi servicio que genero notificaciones

  package com.managment.pavel.managmentgradle; public class GCMIntentService extends GCMBaseIntentService { private static int id =0; final static String GROUP_KEY_GUEST = "group_key_guest"; NotificationManagerCompat notificationManager; public GCMIntentService() { super(SENDER_ID); notificationManager = NotificationManagerCompat.from(getApplicationContext()); } @Override protected void onMessage(Context context, Intent intent) { String message = intent.getStringExtra("content"); generateNotification(context, message); } @Override protected void onError(Context context, String s) { Toast.makeText(context,"Error",Toast.LENGTH_LONG).show(); } @Override protected void onRegistered(Context context, String registrationId) { ServerUtilities.register(context, registrationId); } @Override protected void onUnregistered(Context context, String registrationId) { ServerUtilities.unregister(context, registrationId); } private void generateNotification(Context context, String message) { Intent intent = new Intent(context,MyActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new NotificationCompat.Builder(context) .setContentIntent(pendingIntent) .setSmallIcon(R.drawable.ic_stat_gcm) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_gcm)) .setTicker("Новое сообщение") .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setContentTitle("Сообщение") .setContentText(message) .setGroup(GROUP_KEY_GUEST) .build(); notificationManager.notify(id++, notification); } } 

Debe crear una notificación de resumen con detalles de la anterior. Es esta notificación de resumen que es visible, no la anterior. Es algo como esto:

 private static int id =0; private static int unread_notif = 0; final static String GROUP_KEY_GUEST = "group_key_guest"; private static void generateNotification(Context context, String message) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); Intent intent = new Intent(context,MyActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new NotificationCompat.Builder(context) .setContentIntent(pendingIntent) .setSmallIcon(R.drawable.ic_stat_gcm) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_gcm)) .setTicker("New Message") .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setContentTitle("Message") .setContentText(message) .setGroup(GROUP_KEY_GUEST) .build(); notificationManager.notify(id++, notification); unread_notif++; if (unread_notif>1) { Notification summaryNotification = new NotificationCompat.Builder(mContext) .setContentTitle("Your summary message") .setSmallIcon(R.drawable.ic_small_icon) .setLargeIcon(largeIcon) .setStyle(new NotificationCompat.InboxStyle() .addLine("Details about your first notification") .addLine("Details about your second notification") .setBigContentTitle(Integer.toString(unread_notif)+" new notifications") .setSummaryText("More details in app")) .setGroup(GROUP_KEY_GUEST) .setGroupSummary(true) .build(); notificationManager.notify(id++, summaryNotification); } } 

Consulte la documentación en Agregar una notificación de resumen

Intente inicializar NotificationManagerCompat en generateNotification si la instancia de NotificationManagerCompat es null y quitar código de inicialización form predeterminado constructor:

 private void generateNotification(Context context, String message) { if(notificationManager==null){ notificationManager = NotificationManagerCompat.from(context); } Intent intent = new Intent(context,MyActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new NotificationCompat.Builder(context) .setContentIntent(pendingIntent) .setSmallIcon(R.drawable.ic_stat_gcm) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_gcm)) .setTicker("Новое сообщение") .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setContentTitle("Сообщение") .setContentText(message) .setGroup(GROUP_KEY_GUEST) .build(); notificationManager.notify(id++, notification); } 
  • Servicio de descarga de Android personalizado: proporciona una fila de notificación de progreso por archivo
  • Fragmento no se actualizará después de la notificación de apertura
  • La acción de notificación de Android no se activa (PendingIntent)
  • establecer un temporizador en Android basado en una fecha en la base de datos
  • La aplicación se reinicia si selecciona la aplicación de las aplicaciones recientes sólo cuando se inicia la actividad desde Notification
  • RemoteView no muestra botones en la notificación personalizada
  • Cómo obtener el texto de las notificaciones apiladas en Android
  • Android: ¿Notification.DEFAULT_VIBRATE requiere permiso de vibración?
  • ¿Cómo saber si la función Mostrar notificación está inhabilitada para mi aplicación?
  • NotificationCompat con API 26
  • Eliminación de elemento de lista similar a la notificación en diapositiva en Android
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.