android.app.RemoteServiceException: 在发送通知时,发生了android.app.ActivityThread$H.handleMessage异常。

13

我使用一个服务来显示通知。在一些罕见的设备上(每天 50,000 用户中只有 3 个),我遇到了以下崩溃问题(可以在 Google Play 开发者控制台上看到;仅在 Android 4.x 设备上):

android.app.RemoteServiceException: 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1509)
  at android.os.Handler.dispatchMessage(Handler.java:110)
  at android.os.Looper.loop(Looper.java:193)
  at android.app.ActivityThread.main(ActivityThread.java:5327)
  at java.lang.reflect.Method.invokeNative(Native Method:0)
  at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
  at dalvik.system.NativeStart.main(Native Method:0)

我的通知是用像这样的代码制作的(旧式通知,在Android 6+中已弃用,但仍然有效;在Android 4.x上存在错误,因为该代码已经被弃用):

Notification notification = new Notification(icon, "Custom Notification", when);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
contentView.setImageViewResource(R.id.notifWeatherImageView, WeatherRowTools.getImageForWeatherCode(weatherCodeString));

....some stuff here...

notification.contentView = contentView;
notification.contentIntent = contentIntent;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults = 0;
mNotificationManager.notify(1, notification);

有没有解决这个问题的想法?

非常感谢!!!


奇怪,我有一个完全相同的错误,但只在Android 6和7上出现,在4和5上它可以完美地工作。 - andreszs
我在仅限于Android 4的设备上遇到了同样的问题。我猜测这是一个内部矢量图标错误,不会被修复。 - Shine
1
我在Android 8.1设备上出现了相同的错误。 - Omar Hassan
2个回答

4

我在我的构建中遇到了类似的问题 - 只有Kitkat设备才会大量引发这些问题 - Android操作系统版本:4.4.4、4.4.2、4.2.2、4.0.4。

我们通过更改通知中使用的可绘制对象来修复了类似的问题。

.addAction(R.drawable.ic_forward_black_24dp, VIEW_ACTION, pendingIntentView);

我们停止使用矢量素材,开始使用图片素材。

R.drawable.ic_forward_black_24dp不再使用xml文件(矢量素材),而是现在使用png文件(图片素材)。


0

查看this。即使您没有使用与链接答案相同的SDK,您的问题可能仍然具有相同的原因。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接