user3879225
user3879225

Reputation: 191

How to fix this bug : "android.app.RemoteServiceException: Bad notification posted from package"

The crash info is :

android.app.RemoteServiceException: Bad notification posted from package com.xx.xx:
Couldn't create icon: StatusBarIcon(pkg=com.xx.xx user=0 id=0x7f02035c level=0      visible=true num=0 )  
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1372)  
android.os.Handler.dispatchMessage(Handler.java:102)  
android.os.Looper.loop(Looper.java:136)  
android.app.ActivityThread.main(ActivityThread.java:5139)  
java.lang.reflect.Method.invokeNative(Native Method)  
java.lang.reflect.Method.invoke(Method.java:515)  
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)  
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)  
dalvik.system.NativeStart.main(Native Method)

I think the problem is can not find the drawable resource by the resId. what's your opinion?

Upvotes: 19

Views: 13257

Answers (3)

Raul Pinto
Raul Pinto

Reputation: 1105

TL;DR

When using Firebases ability to set notification, use a PNG instead of a vector by setting default_notification_icon in AndroidManifest.xml

Long description

We had the problem when receiving push notifications on a LG G2 with Android 4.4.2 Fabric (and catlog) showed the following stack trace:

Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package de.xxx.xxx: Couldn't create icon: StatusBarIcon(pkg=de.xxx.xxx=0 id=0x7f0200a6 level=0 visible=true num=0 )
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1367)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5105)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
       at dalvik.system.NativeStart.main(NativeStart.java)

Notice, there is no class in stack trace matching our package. Also, onMessageReceived was called (checked not only with debug break point but also Log.e(TAG, "...")). This means, that it's not us setting the notification, it is Firebase SDK.

Since there is no code involved, I figured (after painful hours of head banging) error must be in AndroidManifest.xml. We are setting another notification icon with the following snippet:

<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_notification" />

Here, @drawable/ic_notification was a vector drawable (SVG). I changed it to a PNG and the crash was gone.

Upvotes: 9

Mohit Singh
Mohit Singh

Reputation: 1450

I was facing the same problem. I noticed I was using Vector Drawable for small icon and this error occurred only on pre-lollipop devices. Using PNG resource for pre-lollipop devices fixed the issue.

Upvotes: 15

jkasten
jkasten

Reputation: 3948

I have seen the "Couldn't create icon: StatusBarIcon" error before and it happens from using an invalid resource id with setSmallIcon on a NotificationCompat.Builder instance. Also if you do not set a small icon at all then your notification will not display. You can use getApplicationInfo().icon as a quick fallback if your code is trying to get the resource id at runtime.

Upvotes: 3

Related Questions