setImageBitmap() is not working

Viewed 12587

I have and ImageView and it is supposed to be filled with an image from Gallery with this code:

Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
            getIntent.setType("image/*");
            Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            pickIntent.setType("image/*");

            Intent chooserIntent = Intent.createChooser(getIntent, "Pick an image.");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});

            startActivityForResult(chooserIntent, PICK_IMAGE_REQUEST);

Now, everything's fine in this part of the code, the problem is in onActivityResult(), exactly in setImageBitmap() because imageView is not adopting the image from Gallery. This is the code from onActivityResult():

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if(requestCode == PICK_IMAGE_REQUEST || resultCode == PromoUpload.RESULT_OK){

        Uri selectedImage = data.getData();
        String[] filepathColumm = {MediaStore.Images.Media.DATA};

        Cursor cursor = getContentResolver().query(selectedImage, filepathColumm, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filepathColumm[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();

        Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
        imagePromo.setImageBitmap(bitmap);
        pictureFlag = 1;

    }

I Toast the picturePath attribute and it's displayed ok, the problem is exactly here:

Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
    imagePromo.setImageBitmap(bitmap);

But I don't know what I'm doing wrong. This is the XML of the ImageView:

<ImageView
        android:id="@+id/imageView_promo"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_centerHorizontal="true"
        android:padding="1dp" />

I also tried selecting images from multiple sizes, but it doesn't seem to work...

2 Answers
Related