working warning notificationcompat notification not for failed example developer create android android-notifications android-8.0-oreo

warning - NotificationChannel problema en Android O



notification channel android example (3)

Recibo un mensaje que dice "Advertencia del desarrollador para el paquete com.google.android.apps.messaging" al enviar un MMS con mensajes de Android versión 2.3.063.

En los registros

08-12 16:57:52.368 7661 7682 W Notification: Use of stream types is deprecated for operations other than volume control 08-12 16:57:52.368 7661 7682 W Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case 08-12 16:57:52.369 1604 3146 E NotificationService: No Channel found for pkg=com.google.android.apps.messaging, channelId=miscellaneous, id=5, tag=null, opPkg=com.google.android.apps.messaging, callingUid=10130, userId=0, incomingUserId=0, notificationUid=10130, notification=Notification(channel=miscellaneous pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xff2a56c6 vis=PRIVATE) 08-12 16:57:52.375 1604 3094 D CompatibilityInfo: mCompatibilityFlags - 0 08-12 16:57:52.375 1604 3094 D CompatibilityInfo: applicationDensity - 480 08-12 16:57:52.375 1604 3094 D CompatibilityInfo: applicationScale - 1.0 08-12 16:57:52.378 7661 7682 I BugleNotifications: Notifying for tag = null, type = RESIZING_NOTIFICATION_ID, notification = Notification(channel=miscellaneous pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xff2a56c6 vis=PRIVATE) 08-12 16:57:52.381 7661 8893 W Notification: Use of stream types is deprecated for operations other than volume control 08-12 16:57:52.381 7661 8893 W Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case 08-12 16:57:52.384 1604 1618 E NotificationService: No Channel found for pkg=com.google.android.apps.messaging, channelId=miscellaneous, id=5, tag=null, opPkg=com.google.android.apps.messaging, callingUid=10130, userId=0, incomingUserId=0, notificationUid=10130, notification=Notification(channel=miscellaneous pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xff2a56c6 vis=PRIVATE) 08-12 16:57:52.384 880 1657 W StreamHAL: Error from HAL stream in function get_presentation_position: Operation not permitted 08-12 16:57:52.387 7661 8893 I BugleNotifications: Notifying for tag = null, type = RESIZING_NOTIFICATION_ID, notification = Notification(channel=miscellaneous pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xff2a56c6 vis=PRIVATE) 08-12 16:57:52.390 1604 1647 E NotificationService: No Channel found for pkg=com.google.android.apps.messaging, channelId=miscellaneous, id=5, tag=null, opPkg=com.google.android.apps.messaging, callingUid=10130, userId=0, incomingUserId=0, notificationUid=10130, notification=Notification(channel=miscellaneous pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x48 color=0xff2a56c6 vis=PRIVATE)

Servicios de Google Play ver 11.3.02
Mensajes de Android 2.3.063
Android 8.0.0

¿Alguien allí para ayudarme?


Como está escrito en la documentación de Android:

developer.android.com/preview/features/…

Si se dirige a Android O y publica una notificación sin especificar un canal de notificaciones válido, la notificación no se publica y el sistema registra un error.

Para resolver este problema, necesita crear un NotificationChannel.

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // The id of the channel. String id = "my_channel_01"; // The user-visible name of the channel. CharSequence name = getString(R.string.channel_name); // The user-visible description of the channel. String description = getString(R.string.channel_description); int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel mChannel = new NotificationChannel(id, name,importance); // Configure the notification channel. mChannel.setDescription(description); mChannel.enableLights(true); // Sets the notification light color for notifications posted to this // channel, if the device supports this feature. mChannel.setLightColor(Color.RED); mChannel.enableVibration(true); mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); mNotificationManager.createNotificationChannel(mChannel);

Y luego asignarlo a su Notificación de esta manera:

mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); // Sets an ID for the notification, so it can be updated. int notifyID = 1; // The id of the channel. String CHANNEL_ID = "my_channel_01"; // Create a notification and set the notification channel. Notification notification = new Notification.Builder(MainActivity.this) .setContentTitle("New Message") .setContentText("You''ve received new messages.") .setSmallIcon(R.drawable.ic_notify_status) .setChannelId(CHANNEL_ID) .build(); // Issue the notification. mNotificationManager.notify(id, notification);

Actualizar:

En caso de que quiera usar NotificationCompat aquí hay un ejemplo simple:

NotificationCompat.Builder mBuilder; mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.mipmap.ic_launcher_icon) .setContentTitle("Title") .setContentText("Text") .setOngoing(true) .setChannelId(id);

De hecho, tiene que usar Notification Builder para establecer la identificación del canal a través de setChannelId ();


Los mensajes en Toast y Logcat que hablen sobre usted deben prestarse 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 .


Otra solución posible es colocar su targetSdkVersion en 25. Los niveles de API recientes solo han traído sticks y no zanahorias. Hay algunas razones para que los desarrolladores apunten apis más recientes.