Her*_*t74 10 android push-notification xiaomi
我们在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)
Run Code Online (Sandbox Code Playgroud)
我在网上发现了很多类似的崩溃报告和文章.这里有几个:
如何解决:android.app.RemoteServiceException:不良通知从包贴*:无法创建图标:StatusBarIcon
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
));
Run Code Online (Sandbox Code Playgroud)
我们还有Facebook通知,必须以类似的方式设置,但是在不同的Notification类上.我不知道它是否相关.除了在制造商和Android版本检查中包装setSmallIcon和/或setLargeIcon方法之外,是否有人遇到过这个或者有任何建议如何解决这个问题?
编辑:我找不到解决方案,但这里有一些新的想法:
我们发布了新版本,但不包括小米用户的通知也没有帮助!现在我认为问题是由ActivityThread.java中的自定义代码引起的.MIUI可能在某些事件中从这里发出通知.这里有几十个Android现货活动,但没有一个会发出通知.但是我们的图标出了问题,所以它们会崩溃.
但是我们的图标出了什么问题?我们有一个ic_notification,可能不会用于此.另一方面,ic_launcher是一个mipmap.这可能是这个吗?但我找不到有关小米和mipmaps的任何问题.
崩溃报告总是在几个应用程序版本中提到相同的资源ID:0x7f0200ad.出于某种原因这是特别的吗?如何对我们的应用进行逆向工程以获取此资源名称?
编辑2:
编辑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之后,他们删除了对小米的默认支持,您必须使用上述链接中的通知.
有其他人受影响吗?
我和用户有同样的问题。我相信这是由以下代码引起的——从APK反编译我没有源代码,它来自shortcutbadger
ResolveInfo.getIconResource() 返回了无效的资源 ID(0x7f0200ad,所有应用程序都相同,看起来只在 MIUI10 上),因此崩溃。
iget-object v1, p0, Lme/leolin/shortcutbadger/impl/XiaomiHomeBadger;->a:Landroid/content/pm/ResolveInfo;
invoke-virtual/range {v1 .. v1}, Landroid/content/pm/ResolveInfo;->getIconResource()I
move-result v1
invoke-virtual {p1, v1}, Landroid/app/Notification$Builder;->setSmallIcon(I)Landroid/app/Notification$Builder;
Run Code Online (Sandbox Code Playgroud)
作为用户,一个简单的修复方法是完全禁用该应用程序的通知 - 至少使其可用。
作为开发人员,使用自己的图标可能会更容易,或者在 ShortcutBadger 中添加一些错误处理。
builder.setSmallIcon(R.drawable.myicon);
Run Code Online (Sandbox Code Playgroud)
更新:
我明白现在发生了什么......在shortcutbadge中有一些奇怪的代码。solveInfo 是默认的 home launcher(MIUI home) Activity,resolveInfo.getIconResource() 是 miui home 的图标
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void tryNewMiuiBadge(Context context, int badgeCount) throws ShortcutBadgeException {
if (resolveInfo == null) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
}
if (resolveInfo != null) {
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(context)
.setContentTitle("")
.setContentText("")
.setSmallIcon(resolveInfo.getIconResource());
Notification notification = builder.build();
Run Code Online (Sandbox Code Playgroud)
从miuihome.apk反编译出来,这里是0x7f0200ad。
<public type="drawable" name="icon_launcher" id="0x7f0200ad" />
Run Code Online (Sandbox Code Playgroud)
那么为什么第 3 方应用程序会尝试使用 miui home 的图标设置通知图标呢?这是出于兼容性原因的一些黑客攻击还是只是一个错误?我用上面的代码片段编写了一个简单的应用程序,在模拟器上进行了测试,它失败了,但没有使应用程序崩溃,在旧的 MIUI 上可能是同样的情况,因为 setSmallIcon(resID) 正在从自己的包中查找带有 resID 的图标。好消息是,这不是 MIUI10 的错误,它应该只发生在使用上述代码的应用程序上。
| 归档时间: |
|
| 查看次数: |
686 次 |
| 最近记录: |