Android Honeycomb - NotificationCompat - ResourcesNotFoundException

111 Views Asked by At

I have created a notification that works well on all Android versions, except on Android 3.x

I use NotificationCompat without custom remote views. The ContentIntent is setted.

This is the stack trace:

PhoneStatusBar: couldn't inflate view for notification it.Ettore.calcolielettrici/0x647980
                                                              android.content.res.Resources$NotFoundException: Resource ID #0x1090087
                                                                  at android.content.res.Resources.getValue(Resources.java:1014)
                                                                  at android.content.res.Resources.loadXmlResourceParser(Resources.java:2039)
                                                                  at android.content.res.Resources.getLayout(Resources.java:853)
                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:389)
                                                                  at android.widget.RemoteViews.apply(RemoteViews.java:1490)
                                                                  at com.android.systemui.statusbar.phone.PhoneStatusBar.makeNotificationView(PhoneStatusBar.java:529)
                                                                  at com.android.systemui.statusbar.phone.PhoneStatusBar.addNotificationViews(PhoneStatusBar.java:558)
                                                                  at com.android.systemui.statusbar.phone.PhoneStatusBar.addNotification(PhoneStatusBar.java:339)
                                                                  at com.android.systemui.statusbar.CommandQueue$H.handleMessage(CommandQueue.java:218)
                                                                  at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                  at android.os.Looper.loop(Looper.java:126)
                                                                  at android.app.ActivityThread.main(ActivityThread.java:3997)
                                                                  at java.lang.reflect.Method.invokeNative(Native Method)
                                                                  at java.lang.reflect.Method.invoke(Method.java:491)
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
                                                                  at dalvik.system.NativeStart.main(Native Method)

and this is my code:

    final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
    notificationBuilder.setSmallIcon(R.drawable.ic_update_white_24dp);
    notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), resIdIconaNotifica));
    notificationBuilder.setContentTitle(context.getString(R.string.notif_upd_aggiornamento_disponibile));
    final String contentText = String.format("%s \"%s\"…", context.getString(R.string.notif_upd_tap_per_aggiornare), context.getString(resIdAppName));
    notificationBuilder.setContentText(contentText);
    notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
    notificationBuilder.setAutoCancel(true);

    final Intent marketIntent = storeManager.getIntentMarket(context.getPackageName());
    final PendingIntent aggiornaPendingIntent = PendingIntent.getActivity(context, 0, marketIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    final Intent annullaIntentReceiver = new Intent(NotificationUpdateCancelReceiver.NAME);
    annullaIntentReceiver.putExtra(KEY_NOTIFICATION_ID, notificationId);
    annullaIntentReceiver.putExtra(KEY_AZIONE, AZIONE_ANNULLA);
    final PendingIntent annullaPendingIntentReceiver = PendingIntent.getBroadcast(context, 0, annullaIntentReceiver, PendingIntent.FLAG_CANCEL_CURRENT);

    final Intent marketIntentReceiver = new Intent(NotificationUpdateCancelReceiver.NAME);
    marketIntentReceiver.putExtra(KEY_NOTIFICATION_ID, notificationId);
    marketIntentReceiver.putExtra(KEY_AZIONE, AZIONE_AGGIORNA);
    marketIntentReceiver.putExtra(Intent.EXTRA_INTENT, marketIntent);
    final PendingIntent aggiornaPendingIntentReceiver = PendingIntent.getBroadcast(context, 1, marketIntentReceiver, PendingIntent.FLAG_CANCEL_CURRENT);

    notificationBuilder.setContentIntent(aggiornaPendingIntent);
    notificationBuilder.addAction(new NotificationCompat.Action(R.drawable.ic_clear_white_24dp, context.getString(R.string.notif_upd_annulla), annullaPendingIntentReceiver));
    notificationBuilder.addAction(new NotificationCompat.Action(R.drawable.ic_update_white_24dp, context.getString(R.string.notif_upd_aggiorna), aggiornaPendingIntentReceiver));

    final Notification notification = notificationBuilder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notificationId, notification);

Thank you so much for your help

UPDATE

I have solved with:

    if(Build.VERSION.SDK_INT >= 14) {
        notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), resIdIconaNotifica));
    }
0

There are 0 best solutions below