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

标签 android android-notifications

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

崩溃日志

Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package com.mypackage: Couldn't create icon: StatusBarIcon(icon=Icon(typ=RESOURCE pkg=com.mypackage id=0x7f08009e) visible user=0 ) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2046) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7406) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at 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 重复我不太确定那里是否有解决方案

如何解决这个问题,或者有一个解决方法来防止它发生,我什至不知道如何重现它以便我可以尝试解决这个问题

最佳答案

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

关于android - 致命异常 : android. app.RemoteServiceException ....无法创建图标:StatusBarIcon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54005921/

相关文章:

android - 有什么方法可以从我的 Android 应用程序中找出 Activity 通知的数量?

android - 以编程方式访问应用程序通知设置

android - SingleChildScrollView 高度到最大高度,图像背景 flutter

java - 防止在 onTouchListener 之前使用按钮

java - 进度对话框未出现

android - 在锁定屏幕中无法单击通知操作按钮

android - 和引擎屏幕上的暂停按钮

java - Android Activity 中的霜玻璃背景效果

java - 带有 PendingIntent.getService 的 startForeground 通知错误?

android - 解析安装未获取 DeviceToken