0

In my application i am select image from the gallery and setting it to the image view.The problem is that the image is not being displayed in the image view.I had debugged but app for the prob,so i found that the method BitmapFactory.decodeFile("image path") is returning null value even thought the path which i am getting is totally fine.

Code

case R.id.imageView:

                intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, GALLERY_CODE);

                break;

if (requestCode == GALLERY_CODE && resultCode == RESULT_OK && null != data) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};

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

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();
            Bitmap image = BitmapFactory.decodeFile(picturePath);
            ivImage.setImageBitmap(image);
        }
    }

I dont know why this is happening. Please do help me out

Anuj Mody
  • 21
  • 1
  • 6

2 Answers2

0

Did you give the permission like these in yours manifest file below minSdk and maxSdk

<uses-feature
    android:name="android.hardware.camera"
    android:required="true" />
Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103
0

Ok so i solved the problem by giving these permissions.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
Anuj Mody
  • 21
  • 1
  • 6