【发布时间】:2014-07-23 17:48:32
【问题描述】:
我将一个可绘制对象传递给位图,然后它会变成一个字节数组并再次返回。然而,这会导致 onReceive 出错。我做错了什么,如何在不损坏接收器的情况下正确传递它?
错误(此处完整:http://pastebin.com/DtBWK8bc):
java.lang.RuntimeException: Error receiving broadcast Intent {
act=com.mytest.accessibility.CATCH_NOTIFICATION flg=0x10 (has extras) } in
nexter.lpvlock.material.com.accessb.ToastOrNotificationTestActivity$1@b10a35a8
服务:
drawable = remotePackageContext.getResources().getDrawable(notification.icon);
Bitmap mIcon = convertToBitmap(drawable, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mIcon.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
Intent mIntent = new Intent(Constants.ACTION_CATCH_NOTIFICATION);
mIntent.putExtra("text", notification.tickerText.toString());
mIntent.putExtra("icon", b);
MyAccessibilityService.this.getApplicationContext().sendBroadcast(mIntent);
Activity(错误指向BitmapFactory行是罪魁祸首):
byte[] b = getIntent().getByteArrayExtra("icon");
Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
iView.setImageBitmap(bmp);
【问题讨论】:
-
请发布整个堆栈跟踪。
-
@CommonsWare 将 pastebin 添加到问题中。
标签: android android-intent bitmap bytearray