Android – java.lang.IllegalArgumentException: contentIntent error requerido por la notificación?

Tengo un servicio en ejecución que actualiza una notificación en la barra de notificaciones cuando recibe un mensaje diciendo que tiene que ser cambiado.

Sin embargo consigo el error siguiente a veces cuando la notificación debe ser puesta al día

java.lang.IllegalArgumentException: contentIntent required 

Aquí está mi código:

Configuración de variables


 int icon = R.drawable.notification; CharSequence tickerText = "Test"; long when = System.currentTimeMillis(); PendingIntent contentIntent; Notification notification = new Notification(icon, tickerText, when); NotificationManager mNotificationManager; 

Creación de NotificationManager


  String ns = Context.NOTIFICATION_SERVICE; mNotificationManager = (NotificationManager) getSystemService(ns); 

Creación de notificaciones


  Intent notificationIntent = new Intent(this, TestsApp.class); contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.flags |= Notification.FLAG_NO_CLEAR; notification.icon = R.drawable.notification3; notification.setLatestEventInfo(this, "Registering", "Test", contentIntent); mNotificationManager.notify(1, notification); 

Actualización de notificación


  notification.icon = R.drawable.notification2; notification.setLatestEventInfo(getApplicationContext(), "Registered", "Test", contentIntent); mNotificationManager.notify(1, notification); 

Así que algo está sucediendo mi contenidoIntent en algún punto de la línea, ¿sería correcto?

Se declara en la parte superior de mi clase de servicio como una variable de miembro y no se utiliza en ningún otro lugar en el código aparte de lo mostrado anteriormente, así que ¿dónde podría ser obtener restablecer a nulo?

Debe establecer el contenido de su notificación.

en tu caso:

 notification.contentIntent = notificationIntent; 

De lo contrario obtendrá el mensaje, que el contenidoInicio de la notificación es nulo, porque no está establecido.

El docu está aquí: http://developer.android.com/reference/android/app/Notification.html#contentIntent

Tengo un pequeño ejemplo aquí: http://united-coders.com/nico-heid/show-progressbar-in-notification-area-like-google-does-when-downloading-from-android

Creo que esto es porque la versión del sistema operativo Android

La versión 2.3 o inferior , debe establecer contentIntent , si no, obtendrá esta excepción.

En mi proyecto, escribo así:

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { Intent intent = new Intent(); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0); mNotification.contentIntent = contentIntent; }

Tal vez esto podría ayudarle!

En tu caso

ContentIntent = PendingIntent.getActivity (esto, 0, notificationIntent, 0);

Si desea utilizar Intents con la misma acción pero diferentes extras:

1) Cambiar

requestCode

Predeterminado "0" en

getActivity (Context context, int requestCode, Intent intent, int flags)

A algo único como `

(int) System.currentTimeMillis();

2)

Notification.contentIntent = notificationIntent;

Ambos pasos son obligatorios porque:

  • La opción 2 no funcionará sin la opción 1.
  • La opción 1 lanzará IllegalArgumentException sin 2.

En mi caso, tuve un código de ejemplo para hacer, con una sola notificación para crear, y también tengo "contentIntent required" error – google me trajo a este hilo: D

La fuente de este problema fueron las citas que copié de un código de ejemplo y lo pegaron en el proyecto eclipse. Cuando eliminé "" y los escribí de nuevo y el problema fue resuelto. Tal vez esto ayuda a alguien.

Estas fueron citas fuente de error: nb.setContentTitle ("Mi primera notificación!"); Nb.setContentText ("Hola");

  • SetLatestEventInfo () no se puede resolver en Android Studio
  • ¿Cómo puedo mantener la notificación de Android abierta hasta que se cierre mi aplicación?
  • Tabhost- establece la posición de la divisa en pestañas Android
  • Notificación de la pantalla de bloqueo de Android Facebook
  • El icono de la barra de notificaciones se vuelve blanco en Android L
  • ¿Cómo contar el número de notificaciones y mostrar un solo icono en Android?
  • Notificación de baja energía del bluetooth
  • Notificaciones de Android: tienen colores en un icono pequeño
  • El icono de la barra de notificaciones se vuelve blanco en Android 5 Lollipop
  • El icono de notificación está en gris
  • ¿Es una práctica común preguntar a los usuarios si desean recibir notificaciones push?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.