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

旧城冷巷雨未停 提交于 2019-11-29 06:53:31

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/24968556/how-to-fix-this-bug-android-app-remoteserviceexception-bad-notification-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!