【发布时间】:2018-12-10 17:23:28
【问题描述】:
我们有很多特定于 Android 6 和 7 上的小米手机的崩溃:
Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package x.y.z: Couldn't create icon: StatusBarIcon(icon=Icon(typ=RESOURCE pkg=x.y.z id=0x7f0200ad) visible user=0 )
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1715)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6358)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
我在网上找到了很多类似的崩溃报告和文章。这里有几个:
https://medium.com/@Miqubel/the-story-of-a-hard-to-fix-bug-ac6ed819cb49
但不同的是,我们仅在小米手机(Android 6 和 7)上存在这些问题,并且可能不会在更新期间出现,因为同一用户在同一发行版本中多次崩溃。
有趣的是,我在网上找不到关于这个特定案例的任何信息,而且我们周围没有任何小米手机。
我将通知设置为:
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, importance);
notificationChannel.enableLights(true);
notificationManager.createNotificationChannel(notificationChannel);
}
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setContentText(body == null ? "" : body)
.setAutoCancel(true)
.setContentIntent(PendingIntent.getActivity(
context,
0,
pendingIntent,
PendingIntent.FLAG_UPDATE_CURRENT
));
我们也有 Facebook 通知,必须以类似的方式设置,但在不同的 Notification 类上。我不知道这是否相关。除了在制造商和 Android 版本检查中包装 setSmallIcon 和/或 setLargeIcon 方法之外,是否有人遇到过这个问题或有任何建议来解决这个问题?
编辑: 我找不到解决方案,但这里有一些新想法:
我们发布了一个新版本,但不包括小米用户 通知没有帮助!现在我认为问题是由 ActivityThread.java 中的自定义代码。 MIUI 可能会触发一个 来自这里的一些事件的通知。有几十个事件 库存 Android 在这里,但没有一个会触发通知。但 我们的图标出了点问题,所以它们崩溃了。
但是我们的图标有什么问题?我们有一个 ic_notification,它 可能不用于此。另一方面,ic_launcher 是一个 贴图。也许是这个?但我找不到任何问题 关于小米和 mipmap。
崩溃报告总是提到跨多个应用版本的相同资源 ID:0x7f0200ad。出于某种原因,这很特别吗?如何对我们的应用进行逆向工程以获取资源名称?
编辑 2:
- 我用apktool对app进行了逆向工程,但是public.xml中没有resource id,貌似和R.java是等价的。我们的 ic_notification 和 ic_launcher 在列表中具有不同的 id。那么这是MIUI找不到的系统资源吗?
编辑 3:
- 其他人有同样问题的第一个证据:
https://xiaomi.eu/community/threads/miui-9.47247/
- 在波兰论坛上找到的临时解决方案:
https://pl.forum.elvenar.com/index.php?threads/problem-z-uruchomieniem-23566.3348/
最后一条评论翻译为: “小米有一个临时解决方案,请尝试在手机设置中禁用Elvenar应用程序强制通知。重新启动应用程序后,错误应该会消失。”
编辑 4:
我们正在使用 ShortcutBadger(版本 1.1.13)。这里说我们应该对小米徽章使用不同的方法:
https://github.com/leolin310148/ShortcutBadger/wiki/Xiaomi-Device-Support
在 1.1.13 版本之后,他们删除了对小米的默认支持,您必须使用上述链接中的通知。
其他受影响的人使用这个吗?
【问题讨论】:
-
你有没有尝试过使用drawable-anydpi-v21
-
不,ic_notification 是一个跨越五个密度的简单 png。但是 ic_launcher 是一个 mipmap。我想知道MIUI是否可以处理mipmaps?我会在几个小时后用关于这个问题的新发现来更新我的问题(还没有解决方案,情况更糟)。
-
提示:
Xiaomi有自己的通知系统。 -
自 2018 年 12 月开始,我的应用程序也开始在 Redmi 设备上出现大量崩溃问题,并且在其他设备上没有发生
-
"0x7f0200ad。由于某种原因,这很特别吗?如何对我们的应用程序进行逆向工程以获取资源名称?"按 ctrl 并单击“R”找到 id。检查 ic_launcher 和 ic_notification。看看他们是否匹配。
标签: android push-notification xiaomi