I had the exact same problem. I need the filename so to be able to upload it to a website.
It worked for me, if I changed the intent to PICK.
This was tested in AVD for Android 4.4 and in AVD for Android 2.1.
Add permission READ_EXTERNAL_STORAGE :
Change the Intent :
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI
);
startActivityForResult(i, 66453666);
/* OLD CODE
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser( intent, "Select Image" ),
66453666
);
*/
I did not have to change my code the get the actual path:
// Convert the image URI to the direct file system path of the image file
public String mf_szGetRealPathFromURI(final Context context, final Uri ac_Uri )
{
String result = "";
boolean isok = false;
Cursor cursor = null;
try {
String[] proj = { MediaStore.Images.Media.DATA };
cursor = context.getContentResolver().query(ac_Uri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
result = cursor.getString(column_index);
isok = true;
} finally {
if (cursor != null) {
cursor.close();
}
}
return isok ? result : "";
}