How to fix: android.app.RemoteServiceException: Bad notification posted from package *: Couldn't create icon: StatusBarIcon

android app remoteserviceexception bad notification posted from package couldn t expand remoteviews
android.app.remoteserviceexception handlemessage
bad notification posted from package com example background couldn t create icon: statusbaricon
android.app.remoteserviceexception android 9
android.app.remoteserviceexception android 8
bad notification for startforeground
fatal exception android.app.remoteserviceexception can't deliver broadcast
android vector icons

I'm seeing the following exception in crash logs:

android.app.RemoteServiceException: Bad notification posted from package com.my.package: Couldn't create icon: StatusBarIcon(pkg=com.my.package user=0 id=0x7f02015d level=0 visible=true num=0 )
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1456)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5487)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)

I'm posting my Notification from an IntentService from a PendingIntent set via the AlarmManager using the following method. All values passed in here are from the bundle extras in the PendingIntent / IntentService.

/**
 * Notification 
 *
 * @param c
 * @param intent
 * @param notificationId
 * @param title
 * @param message
 * @param largeIcon
 * @param smallIcon
 */
public static void showNotification(Context c, Intent intent,
        int notificationId, String title, String message, int largeIcon,
        int smallIcon) {
    PendingIntent detailsIntent = PendingIntent.getActivity(c,
            notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // BUILD
    NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(
            c);
    // TITLE
    mNotifyBuilder.setContentTitle(title).setContentText(message);

    // ICONS
    mNotifyBuilder.setSmallIcon(smallIcon);
    if (Util.isAndroidOSAtLeast(Build.VERSION_CODES.HONEYCOMB)) {
        Bitmap large_icon_bmp = ((BitmapDrawable) c.getResources()
                .getDrawable(largeIcon)).getBitmap();
        mNotifyBuilder.setLargeIcon(large_icon_bmp);
    }

    mNotifyBuilder.setContentIntent(detailsIntent);
    mNotifyBuilder.setVibrate(new long[] { 500, 1500 });
    mNotifyBuilder.setTicker(message);
    mNotifyBuilder.setContentText(message);

    // NOTIFY
    NotificationManager nm = (NotificationManager) c
            .getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(notificationId, mNotifyBuilder.build());
}

From what I've seen of other answers - the exception I'm seeing happens when setSmallIcon() is not called properly.

I've checked and double checked that the Resource IDs being passed are all correct.

What was happening was, I was including the integer reference to the icon in the PendingIntent bundle, and that integer was later being referenced while being posted to the NotificationManager.

In between getting the integer reference and the pending intent going off, the app was updated and all of the drawable references changed. The integer that used to reference the correct drawable now referenced either the incorrect drawable or none at all (none at all - causing this crash)

Bad notification posted from package : Couldn't create icon , Exception: android.app.RemoteServiceException: Bad notification posted from package : Couldn't create icon: Fix. Use alpha only icon. Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

Using VectorXml inside your notification has been known to cause this issue. Use png's

App crash with vector drawable as notification icon · Issue #3 , Emulator: Nexus 5, API 23 android.app.RemoteServiceException: Bad notification posted from package com.xxx.xxx: Couldn't create icon: StatusBarIcon​(pkg=com.example.background=0 Bug fixing from GitHub issues … FCM - How to fix android.app.RemoteServiceException: Bad notification posted from package Couldn't expand RemoteViews for: StatusBarNotification Ask Question Asked 1 year, 10 months ago

Don't use SVG on Kitkat!

I had the same issue every time when I wanted to show a notification on Kitkat. What caused the problem for me is that I have defined every icon in xml (from svg), the small icon and the action icon also. After I have replaced them with png-s the problem solved at my side.

App crash when display notification · Issue #255 · OneSignal , RemoteServiceException: Bad notification posted from package com.gobike.​consumer: Couldn't create icon: StatusBarIcon(pkg=com.gobike.consumeruser=0 id=0x7f0200f9 level=0 Looper.loop(Looper.java:194) at android.app. If you delete your custom small icon does it resolve the issue? Can you try  I'm receiving this issue on crashlytics only on Motorola devices with Android Nougat: Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package br.com.vivadecora.app: Couldn't expand RemoteViews for: Statu

android.app.RemoteServiceException: Bad notification posted

I had the same issue, but I was resolved. My problem is ".xml file" of Remote view.

In my xml file I was added one View in between the LinearLayout for divider.

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:id="@+id/view"
    android:background="#000000" />

The above View component creating the Bad notification exception. This Exception reason is only xml file of Remoteviews.

After removing that View component, My code executed properly, without any exception. So I felt that Notification drawer not accepting any customized views.

So you don't draw any thing like the above view in the .xml file of RemoteView object.

How to fix: android.app.RemoteServiceException: Bad , RemoteServiceException: Bad notification posted from package *: Couldn't create icon: I'm seeing the following exception in crash logs: android.app. Problem: Bad notification posted from package com.notify: Couldn't create icon 09-19 21:10:05.725 1600-1600/? W/ResourceType: No known package when getting value for resource number 0x2714000e 09-19 21:10:05.725 1600-1600/?

In my app, this kind of bug happens only during upgrading. If the resource id changes in the newer version, Android RemoteView may fail to find the resource and throw out the RemoteServiceException. If you publish a 3rd version and do not change the resource id, the bugs may disappear only temporarily.

It is possible to reduce this kind of bugs by editing res/values/public.xml and res/values/ids.xml. Compiler will generate an individual resource id if the resource id is not in public.xml or ids.xml. When u change the resource name or add some new resources, the id may change and some devices may fail to find it.

So the step is as following:

  1. Decompile the apk file and in res/values find the public.xml and ids.xml
  2. Find all resources related to RemoteView in your app and copy them ( strings, dimen, drawable, layout, id, color... )
  3. Create public.xml and ids.xml under res/values in your source code and paste the lines u just copied

Note:

Gradle 1.3.0 and above ignore the local public.xml. To make it work, u need to add some script in your build.gradle

afterEvaluate {
    for (variant in android.applicationVariants) {
        def scope = variant.getVariantData().getScope()
        String mergeTaskName = scope.getMergeResourcesTask().name
        def mergeTask = tasks.getByName(mergeTaskName)
        mergeTask.doLast {
            copy {
                int i=0
                from(android.sourceSets.main.res.srcDirs) {
                    include 'values/public.xml'
                    rename 'public.xml', (i == 0? "public.xml": "public_${i}.xml")
                    i++
                }
                into(mergeTask.outputDir)
            }
        }
    }
}

Note: This script does not support submodules project. I am trying to fix it.

How to fix Xiaomi specific RemoteServiceException with notification , RemoteServiceException: Bad notification posted from package x.y.z: pkg=​x.y.z id=0x7f0200ad) visible user=0 ) at android.app. RemoteServiceException: Bad notification posted from package *: Couldn't create icon:  Notification icon: App crash when publishing a post Bad notification posted from package org.wordpress.android: Couldn't expand RemoteViews for

android.app.RemoteServiceException, RemoteServiceException: Bad notification posted from package because after some research I found that could be an Android OS problem @AhmadullahSaikat The SDK does use android.support.v7, we use the TextView directly instead of going through a support library. Same for the image view. Please point the the exact line of code in our SDK if I am mistaken in a new issue.

New, It happens for users using Android 6 /6.0.1 / 7.0 on various Xiaomi devices. Bad notification posted from package com.houzz.app: Couldn't create /how-to-​fix-xiaomi-specific-remoteserviceexception-with-notification-icon android.app.RemoteServiceException: Bad notification posted. I had the same issue, but I was resolved. My problem is ".xml file" of Remote view. In my xml file I was added one View in between the LinearLayout for divider.

We have a lot of crashes specific to Xiaomi phones on Android 6 and 7: android.app.RemoteServiceException: Bad notification posted from package x.y.z: Couldn't create icon: How to fix: android.app.RemoteServiceException: Bad notification posted from package *: Couldn't create icon: StatusBarIcon. RemoteServiceException when using in Notifications TRACE=android.app.RemoteServiceException: Bad notification posted from package com.my.appname: Couldn't create

Comments
  • I'm experiencing the same error (crash reports from a live app). I can't reproduce it on my device. I'm currently thinking it's because people modified the .apk
  • Guys, in which way can I solve this problem. I use pngs, but very rarely app crashes
  • Bizarre. In other words, this isn't fixable is it? I'm seeing the same crashes in my app.
  • It does not seem fixable. I will, in the future, have to devise a different way to go about posting notifications with images in the future....
  • What if we try to set the textSize of the remote view as ret.setInt(id, "setTextSize", 20); It also crashes. I know we also have to provide the units, but how do I do that with such method signature. Any pointer??
  • I have the same problem. Currently researching the possibility of using a custom view utilizing the RemoteViews.ActionException in order to handle the exception raised in this scenario. I'll report if I find a way to make it work. Another approach is to get the drawables used in the notification to get the same ID under R.drawable when compiling so that the icon get the same ID in subsequent builds (but I still haven't figured out how to do it and wether it's even possible).
  • In case you want to reference R.drawable.my_image, it's safer to save it to bundle as a string( bundle.putString("img", "my_image")and then convert when needed to actual @DrawableRes integer as follows: ctx.resources.getIdentifier(bundle.getString("img"), "drawable", ctx.packageName)
  • Only PNGs were being used.
  • In my case, I had vector in drawable folder and png's in drawable-hdpi, xhdpi, etc. But there was no png for drawable-mdpi, and it crashed on MDPI device on posting a notification.
  • I can confirm. Vector drawables in notifications cause RemoteServiceException on KitKat.
  • In the case of KitKat, the problem was resolved when I replaced the XML with PNG in: new NotificationCompat.Builder(context, CHANNEL_ID).setSmallIcon(R.drawable.my_icon)
  • This worked for me. I was running API 19 and used a SVG file for notification icon and was giving me this error, until I switched it to a small png icon
  • In my case, I had vector in drawable folder and png's in drawable-hdpi, xhdpi, etc. But there was no png for drawable-mdpi, and it crashed on MDPI device on posting a notification.
  • I've passed vector image as a resource and I think it caused the crashes on oneplus/android 6 devices. Not sure for 100%.