致命异常:android.app.RemoteServiceException...。无法创建图标:StatusBarIcon

时间:2019-01-02 11:56:14

标签: android android-notifications

我的实时用户已在Crashlytics上发布了数百次此异常,而且我无法在5种不同的设备上重现此异常

崩溃日志

  

致命异常:android.app.RemoteServiceException:从com.mypackage包发布的错误通知:无法创建图标:StatusBarIcon(icon = Icon(typ = RESOURCE pkg = com.mypackage id = 0x7f08009e)可见的用户= 0)          在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2046)          在android.os.Handler.dispatchMessage(Handler.java:102)          在android.os.Looper.loop(Looper.java:148)          在android.app.ActivityThread.main(ActivityThread.java:7406)          在java.lang.reflect.Method.invoke(Method.java)          在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1230)          在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

我发布通知的唯一地方仅来自FirebaseMessagingService 这是用于发布通知的代码

private fun sendNotification(remoteMessage: RemoteMessage) {
    val intent = Intent(this, MainActivity::class.java)
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
    val pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT)
    val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
    val notificationBuilder = NotificationCompat.Builder(this, "")
            .setContentText(remoteMessage.notification?.body)
            .setContentTitle(remoteMessage.notification?.title)
            .setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_notification)
            .setSound(defaultSoundUri)
            .setColor(ContextCompat.getColor(this, R.color.blue_accent_color))
            .setContentIntent(pendingIntent)
    val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build())
}

要提及的内容: 1-可绘制对象不是矢量可绘制对象,它是在(mdpi,hdpi,xhdpi。xxhdpi,xxxhdpi)中找到的具有透明背景的png
2-绘图由Android Assets Studio
创建 3-这可能与此Question相同,我不确定那里是否有解决方法

如何解决此问题,或者有一种解决方法来防止它发生,我什至不知道如何重现它,以便我可以尝试对这个问题进行故障排除

1 个答案:

答案 0 :(得分:0)

在将项目迁移到早期版本的SDK版本23之后,我遇到了这个问题。我发现该项目有两个版本的tne .xml文件,其中包含小图标资源(在我的情况下为res / drawable / ic_launcher_foreground.xml和res / drawable-v24 / ic_launcher_foreground.xml)。当我删除与v24关联的.xml时,崩溃停止了。