unable to decode ContentResolver.openInputStream(uri)

1k Views Asked by At

I'm having trouble decoding InputStream returned from contentResolver.optInputStream(uri)

Since Uri is image i first tried to decode stream with BitmapFactory.decodeStream. Returned bitmap is null

InputStream is = getContentResolver().openInputStream(imageUri);
Bitmap bitmap = BitmapFactory.decodeStream(is);//this is null

Then i tried something like this to see if maybe uri is not image, but resulting byte array is empty

InputStream is = getContentResolver().openInputStream(imageUri);
ByteArrayOutputStream out = new ByteArrayOutputStream();
final byte[] b = new byte[8192];
for (int r; (r = is.read(b)) != -1;) {
    out.write(b, 0, r);
}

out.toByteArray(); is empty array

Uri is in this format: content://com.android.providers.media.documents/document/image:19
I also tried with different uris but same problem.

EDIT: Code used to pick uri is this:

intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, null), PICK_PHOTO_REQUEST);
0

There are 0 best solutions below