我將一個drawable傳遞給位圖,然後將其轉化爲一個bytearray並再次返回。但是,這會導致onReceive發生錯誤。我做錯了什麼,以及如何正確傳遞它而不會破壞接收器?從服務到意圖的位圖導致RuntimeException接收到廣播意圖
錯誤(這裏充分:http://pastebin.com/DtBWK8bc):
java.lang.RuntimeException: Error receiving broadcast Intent {
act=com.mytest.accessibility.CATCH_NOTIFICATION flg=0x10 (has extras) } in
nexter[email protected]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);
活動(錯誤指向BitmapFactory行是罪魁禍首):
byte[] b = getIntent().getByteArrayExtra("icon");
Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
iView.setImageBitmap(bmp);
請張貼整個堆棧跟蹤。 – CommonsWare
@CommonsWare添加pastebin的問題。 – Carl