I trying to pick an image from gallery and set the bitmap to my imageview, but I have a problem: in my device, works well, but it doesn't work in other.
I start the image picker in my fragment as follow:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
And this is my onActivityResult
:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
Log.d("ResultCode",resultCode+"");
switch (requestCode) {
case SELECT_PHOTO:
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = imageReturnedIntent.getData();
try {
Bitmap imagen = decodeUri(selectedImage);
// Works on my device (because resultCode = RESULT_OK) but doesn't work in others (because resultCode = 0)
((ImageView) findViewById(R.id.myimage)).setImageBitmap(imagen);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
I would appreciate any help, I'm a little desperate. x_x
I have had this issue... so much fun. There are three different ways to choose photos, and like you said, for some reason it doesn't always work properly on all devices. After many hours of torture, I found this worked consistently: