【发布时间】:2019-01-02 11:56:14
【问题描述】:
我的现场用户在 Crashlytics 上发布了数百次此异常,但我无法在 5 种不同的设备上重现它一次
崩溃日志
致命异常:android.app.RemoteServiceException:从包 com.mypackage 发布的错误通知:无法创建图标:StatusBarIcon(icon=Icon(typ=RESOURCE pkg=com.mypackage id=0x7f08009e) visible user=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- drawable 不是矢量可绘制的,它是一个具有透明背景的 png,位于 (mdpi, hdpi, xhdpi.xxhdpi, xxxhdpi)
2- drawable 是由Android Assets Studio创建的
3- 这可能与 Question 重复,我不太确定那里是否有解决方案
如何解决这个问题,或者有一个解决方法来防止它发生,我什至不知道如何重现它以便我可以尝试解决这个问题
【问题讨论】:
-
您找到任何解决方案了吗?
-
不,我没有找到解决办法!
标签: android android-notifications