1

I am new to android. I want to pick image from gallery. For 4.3 and below following code works fine. But not in 4.4. Please help.

buttonLoadImage.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View arg0) {

        Intent i = new Intent(
                Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

        startActivityForResult(i, RESULT_LOAD_IMAGE);
    }
  });
}


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

if (requestCode == RESULT_LOAD_IMAGE && 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();

    ImageView imageView = (ImageView) findViewById(R.id.imageView1);
    imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

}
  • Please refer to this link.http://stackoverflow.com/questions/19834842/android-gallery-on-kitkat-returns-different-uri-for-intent-action-get-content – Rain Sep 18 '14 at 13:38

1 Answers1

0

Looks like they have completely changed the way to pick a photo from the Gallery in Android 4.4, you have to use the Storage Access Framework as described here:

Storage Access Framework

mbonness
  • 1,612
  • 1
  • 18
  • 20