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:
- Cómo cambiar el atributo 'android: autoStart' de ViewFlipper en RemoteViews mediante programación?
- Cómo cambiar la imagen en el widget de la aplicación mediante programación en android
- RemoteViews setViewVisibility en Android Widget
- Android Widget con ListView que muestra sólo vistas de carga
- No se pudo expandir RemoteViews para: StatusBarNotification
- 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
- ¿Cómo utilizar Glide en remoteViews?
- Imagen en Widget
- Color del fondo del framelayout del remoteview
- RemoteView no muestra botones en la notificación personalizada
- Manera fiable de recuperar los detalles de StatusbarNotification (título, texto de notificación)
- Pasar objeto personalizado parcelable extra o en ArrayList a RemoteViewsService rompe appwidget
- AppCompat 23.2 utiliza VectorDrawableCompat con RemoteViews (AppWidget) en la API <21
- Android ListView en el widget onClick no funciona
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)