No se pudo expandir RemoteViews – Notificación incorrecta

Últimamente he estado recibiendo más y más informes de usuarios que reciben un error de RemoteServiceException. El seguimiento de la pila que se me da cada vez es el siguiente:

android.app.RemoteServiceException: Bad notification posted from package com.smithyproductions.fasttracks: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.smithyproductions.fasttracks id=311095 tag=null score=0 notn=Notification(pri=0 contentView=com.smithyproductions.fasttracks/0x7f03007d vibrate=null sound=null defaults=0x0 flags=0x62 kind=[null]) user=UserHandle{0}) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:153) at android.app.ActivityThread.main(ActivityThread.java:5341) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:929) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696) at dalvik.system.NativeStart.main(NativeStart.java) 

Nunca puedo reproducir el problema en un HTC Sensation o HTC One X, lo que me lleva a creer que puede ser específico del dispositivo. He recibido informes de este error de los siguientes dispositivos:

  • Huawei G610 U15
  • Bq Aquaris 5 HD
  • Enspert Stairway
  • JYT JY-G5

… y todos ellos están ejecutando Android 4.2.1 – tal vez hay un error con esa versión de Android?

He explorado el Internet y StackOverflow para las personas con problemas similares y aunque hay un montón de gente con este problema la mayoría de las veces la razón por la que no estaba funcionando correctamente para ellos era debido a identificadores de recursos incorrectos o utilizando vistas no compatibles en el RemoteViews. No entiendo cómo podría ser algo que estoy haciendo mal si funciona en el 98% de los dispositivos, pero no quiero decirles a estas personas con el problema que no hay nada que pueda hacer al respecto.

En cuanto a la forma en que creo la notificación, uso la clase NotificationCompat.Builder junto con una RemoteViews personalizada, básicamente es una notificación de reproductor de música, por lo que también tiene algunos ImageButtons en ella.

Aquí está mi código donde configuro la notificación:

 PendingIntent pi = PendingIntent.getActivity( getApplicationContext(), 0, new Intent(getApplicationContext(), Showcase.class), PendingIntent.FLAG_UPDATE_CURRENT); RemoteViews smallContentView = new RemoteViews(getPackageName(), R.layout.notif_layout); nowPlayingNotification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon) .setContentTitle( "Playing: " + playbackManager.getCurrentTrack() .getName()).setContentIntent(pi) .setOngoing(true) .setWhen(System.currentTimeMillis()) .setContent(smallContentView).build(); 

Y luego establecer todas las devoluciones de llamada para los botones RemoteViews:

 Intent playIntent = new Intent(this, RemoteControlReceiver.class); playIntent.setAction(ACTION_TOGGLE_PLAYBACK); PendingIntent playPausePendingIntent = PendingIntent.getBroadcast(this, 0, playIntent, 0); Intent nextIntent = new Intent(this, RemoteControlReceiver.class); nextIntent.setAction(ACTION_SKIP); PendingIntent nextPendingIntent = PendingIntent.getBroadcast(this, 0, nextIntent, 0); Intent stopIntent = new Intent(this, RemoteControlReceiver.class); stopIntent.setAction(ACTION_STOP); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0); nowPlayingNotification.contentView.setTextViewText(R.id.title, playbackManager.getCurrentTrack().getName()); nowPlayingNotification.contentView.setProgressBar( android.R.id.progress, 100, mediaProgress, false); if (notificationIconMixBitmap != null) nowPlayingNotification.contentView.setImageViewBitmap(R.id.icon, notificationIconMixBitmap); else { nowPlayingNotification.contentView.setImageViewResource(R.id.icon, R.drawable.notification_icon); } nowPlayingNotification.contentView.setOnClickPendingIntent( R.id.playPause, playPausePendingIntent); if (playbackManager.getCurrentPlaybackState() == State.Paused) { nowPlayingNotification.contentView.setImageViewResource( R.id.playPause, R.drawable.play_icon_solid); } else { nowPlayingNotification.contentView.setImageViewResource( R.id.playPause, R.drawable.pause_icon_solid); } if (!playbackManager.isSkipAllowed()) { nowPlayingNotification.contentView.setImageViewResource(R.id.next, R.drawable.next_icon_disabled); } else { nowPlayingNotification.contentView.setImageViewResource(R.id.next, R.drawable.next_icon_solid); } if (playbackManager.getCurrentPlaybackState() == State.Preparing) { nowPlayingNotification.contentView.setProgressBar( android.R.id.progress, 100, mediaProgress, true); } nowPlayingNotification.contentView.setOnClickPendingIntent(R.id.next, nextPendingIntent); nowPlayingNotification.contentView.setOnClickPendingIntent(R.id.close, stopPendingIntent); 

seguido por

 mNotificationManager.notify(NOTIFICATION_ID, nowPlayingNotification); 

Si alguien sabe algo que podría ayudar, tal vez un error reconocido en 4.2.1, sería muy apreciado! Gracias

Tuve el mismo problema con mi teléfono.

Usted crea la notificación con el código abajo:

 nowPlayingNotification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon) .setContentTitle( "Playing: " + playbackManager.getCurrentTrack() .getName()).setContentIntent(pi) 

La aplicación se bloquea si la intención pendiente -> pi especificando la intención de iniciarse se establece en null como se muestra a continuación:

  PendingIntent pi= PendingIntent.getActivity( getApplicationContext(), 0, ***null***, 0 ); 

Reemplace null con nuevo Intent () y pruebe si resuelve el problema.

En Gingerbread .setcontentIntent (intención) es obligatorio de lo contrario IllegalArgumentException se lanzará. Pero en Jellybean no se lanza ninguna excepción si eliminamos .setcontentIntent (intención)

  • Las vistas de StackedWidget no se muestran
  • RemoteViewsFactory llamado getViewAt cuando el dataset vacío
  • Android ¿Cómo setWeight de una RemoteView?
  • ¿Es posible agregar a los oyentes onclick a las vistas remotas en android
  • RemoteView y setGravity
  • Obtener el ancho del panel de notificaciones de Android
  • ¿Es seguro confiar en la llamada a onDataSetChanged () después de onCreated () en RemoteViewsFactory de un AppWidget
  • Conserve la relación de aspecto de la imagen en el widget de aplicación GridView
  • Notificaciones de Remote View de Android
  • ¿Cómo crear una notificación con una vista personalizada, pero con una apariencia nativa?
  • Cómo crear ListView con la ayuda de remoteview?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.