Bitmap From Service To Intent Causing Runtimeexception Receiving Broadcast Intent
Solution 1:
I finally got it to work! Most of the credit goes to the user @MartinPelant (ref: https://stackoverflow.com/a/16258120/2423004).
I do not know why that error did pop up, but I'm assuming there was an issue with the bitmap or bytearray. I'm going to assume the bitmap did not contain a proper bitmap/drawable. But in my usage I was looking for the notification icon of incoming notifications using AccessibilityService. If you came here looking for the same answer then here. It can be (properly) retrieved by looking for the first ImageView within a notification:
@Override
publicvoidonAccessibilityEvent(AccessibilityEvent event) {
Log.i("onAccessibilityEvent", "");
if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
if (event.getParcelableData() instanceof Notification) {
Notification notification = (Notification) event.getParcelableData();
try {
extractImage(notification.tickerView);
} catch (Exception e) {
e.printStackTrace();
extractImage(notification.contentView);
}
}
}
The method for extracting the notification can be found at the referred link.
I'm posting this as an answer as there are literally no decent explanation of retrieving anything but text or package name from AccessibilityService. The furthest one will get without this is passing a drawable/bitmap through intent which in the end will lead to the above question's error.
EDIT And just so it's even clearer, have this within the extractImage method to pass it to your activity:
BitmapmIcon= convertToBitmap(drawable, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
ByteArrayOutputStreambaos=newByteArrayOutputStream();
mIcon.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
IntentmIntent=newIntent(Constants.ACTION_CATCH_NOTIFICATION);
mIntent.putExtra("icon", b);
MyAccessibilityService.this.getApplicationContext().sendBroadcast(mIntent);
Post a Comment for "Bitmap From Service To Intent Causing Runtimeexception Receiving Broadcast Intent"