studio showing oreo notification not example developer android android-notifications android-8.0-oreo

android - showing - Error al publicar la notificación en el canal "nulo" La API de destino es 26



notification channel android (6)

Cuando se dirige a Android 8.0 (nivel de API 26), debe implementar uno o más canales de notificación para mostrar notificaciones a sus usuarios.

int NOTIFICATION_ID = 234; NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { String CHANNEL_ID = "my_channel_01"; CharSequence name = "my_channel"; String Description = "This is my channel"; int importance = NotificationManager.IMPORTANCE_HIGH; NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance); mChannel.setDescription(Description); mChannel.enableLights(true); mChannel.setLightColor(Color.RED); mChannel.enableVibration(true); mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); mChannel.setShowBadge(false); notificationManager.createNotificationChannel(mChannel); } NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, CHANNEL_ID) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle(title) .setContentText(message); Intent resultIntent = new Intent(ctx, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); notificationManager.notify(NOTIFICATION_ID, builder.build());

Dos registro que muestra

1: El uso de tipos de flujo está en desuso para operaciones que no sean el control de volumen

2: Consulte la documentación de setSound () para saber qué usar en lugar de con android.media.AudioAttributes para calificar su caso de uso de reproducción


Este problema está relacionado con la versión anterior de FCM.

Actualice su dependencia a com.google.firebase:firebase-messaging:15.0.2 o superior.

Esto solucionará el error.

failed to post notification on channel null

cuando su aplicación recibe notificaciones en segundo plano porque ahora Firebase proporciona un canal de notificación predeterminado con configuraciones básicas.

Pero también puede especificar el canal de notificación predeterminado para FCM en el manifiesto.

<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id"/>

Para aprender más here


La respuesta de Gulzar Bhat funciona perfectamente si su API mínima es Oreo. Sin embargo, si el mínimo es menor, debe ajustar el código de NotificationChannel en una comprobación de nivel de plataforma. Después de eso, todavía puedes usar el ID, que se ignorará antes de Oreo:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, importance); notificationChannel.enableLights(true); notificationChannel.setLightColor(Color.RED); notificationChannel.enableVibration(true); notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); notificationManager.createNotificationChannel(notificationChannel); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify((int)(System.currentTimeMillis()/1000), mBuilder.build());


Primero crea el canal de notificación:

public static final String NOTIFICATION_CHANNEL_ID = "4655"; //Notification Channel CharSequence channelName = NOTIFICATION_CHANNEL_NAME; int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, importance); notificationChannel.enableLights(true); notificationChannel.setLightColor(Color.RED); notificationChannel.enableVibration(true); notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(notificationChannel);

luego usa el id del canal en el constructor:

final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID) .setDefaults(Notification.DEFAULT_ALL) .setSmallIcon(R.drawable.ic_timers) .setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}) .setSound(null) .setContent(contentView) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setLargeIcon(picture) .setTicker(sTimer) .setContentIntent(timerListIntent) .setAutoCancel(false);


Puede resolver esto de dos maneras, pero para ambas necesita crear un canal de notificación con un ID de canal específico.

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); String id = "my_channel_01"; int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel mChannel = new NotificationChannel(id, name,importance); mChannel.enableLights(true); mNotificationManager.createNotificationChannel(mChannel);

La primera forma es establecer el canal para la notificación en el constructor:

Notification notification = new Notification.Builder(MainActivity.this , id).setContentTitle("Title"); mNotificationManager.notify("your_notification_id", notification);

La segunda forma es configurar el canal mediante Notificiation.Builder.setChannelId ()

Notification notification = new Notification.Builder(MainActivity.this).setContentTitle("Title"). setChannelId(id); mNotificationManager.notify("your_notification_id", notification);

Espero que esto ayude


Si obtienes este error deberás prestar atención a 2 artículos y ordenarlos:

  1. NotificationChannel mChannel = new NotificationChannel(id, name, importance);
  2. builder = new NotificationCompat.Builder(this, id);

También NotificationManager notifManager y NotificationChannel mChannel se crean solo una vez.

Hay setters requeridos para la notificación:

builder.setContentTitle() // required .setSmallIcon() // required .setContentText() // required

Ver el ejemplo en On Android 8.1 API 27 no se muestra la notificación .