I am trying to get an Image file from the gallery:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),
        GET_IMAGE_FROM_GALLERY);
The message "Selecture Picture" is not shown as a Toast.
And in onActivityResult();
Uri selectedImageUri = data.getData(); //log shows proper URI
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImageUri,
        projection, null, null, null);
int column_index = cursor
        .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String selectedImagePath = cursor.getString(column_index);
cursor.getString(column_index) returns Null.
I am testing it on Nexus 4.
EDIT:
Looks like this is a problem with Android 4.4, I have see other apps failing too.
Convert content:// URI to actual path in Android 4.4
Use this :
String selectedImagePath = null;
Uri selectedImageUri = data.getData();
Cursor cursor = activity.getContentResolver().query(
    selectedImageUri, null, null, null, null);
if (cursor == null) { 
    selectedImagePath = selectedImageUri.getPath();
} else {
    cursor.moveToFirst();
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
    selectedImagePath = cursor.getString(idx);
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With