通知/服务 - 无法将位图复制到parcel blob

时间:2018-06-18 08:26:11

标签: android service android-notifications

在我的应用程序中,我启动前台服务并为其创建通知:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId);
...
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.icon));
...

这会在我的一个用户设备上引发异常(例如java.lang.RuntimeException: Could not copy bitmap to parcel blob.例外)。

我的图标确实有默认尺寸和小尺寸,不知道为什么他们会在一台设备上出现问题。

有谁知道真正的问题是什么?我怎么能避免这个问题或优雅地处理这个案子?似乎是一个记忆问题。

Mipmap图标

我已经包含以下图标:

  • mdpi(48x48,3,51kB)
  • hdpi(72x72,6,65kB)
  • xhdpi(96x96,9,08kB)
  • xxhdpi(144x144,27.23kB)
  • xxxhdpi(192x192,22,0kB)

异常

java.lang.RuntimeException: Unable to start service com.my.app.services.OverlayService@ea0edcc with Intent { act=RESUME cmp=com.my.app/.services.OverlayService }: java.lang.RuntimeException: Could not copy bitmap to parcel blob.
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3079)
    at android.app.ActivityThread.access$2200(ActivityThread.java:163)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5585)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Caused by: java.lang.RuntimeException: Could not copy bitmap to parcel blob.
    at android.graphics.Bitmap.nativeWriteToParcel(Native Method)
    at android.graphics.Bitmap.writeToParcel(Bitmap.java:1541)
    at android.graphics.drawable.Icon.writeToParcel(Icon.java:705)
    at android.os.Parcel.writeParcelable(Parcel.java:1437)
    at android.os.Parcel.writeValue(Parcel.java:1343)
    at android.os.Parcel.writeArrayMapInternal(Parcel.java:686)
    at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330)
    at android.os.Bundle.writeToParcel(Bundle.java:1079)
    at android.os.Parcel.writeBundle(Parcel.java:711)
    at android.app.Notification.writeToParcel(Notification.java:1731)
    at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:701)
    at android.app.NotificationManager.notify(NotificationManager.java:230)
    at android.app.NotificationManager.notify(NotificationManager.java:194)
    at com.my.app.services.BaseOverlayService.a(SourceFile:39)
    at com.my.app.services.BaseOverlayService.a(SourceFile:23)
    at com.my.app.services.OverlayService.onStartCommand(SourceFile:136)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3062)

0 个答案:

没有答案