Skip to content

Instantly share code, notes, and snippets.

@akexorcist
Created June 6, 2014 08:19
Show Gist options
  • Save akexorcist/4a01eec6e5210a779ec2 to your computer and use it in GitHub Desktop.
Save akexorcist/4a01eec6e5210a779ec2 to your computer and use it in GitHub Desktop.
Get Real Path from URI which choose from intent
// Image Media Path : /document/image:48645
// Real file Path : /storage/emulated/0/DCIM/Camera/IMG_20140606_123326982.jpg
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_GALLERY && resultCode == RESULT_OK) {
Uri uri = data.getData();
String path = getRealPathFromURI(getApplicationContext(), uri);
Log.e("Check", "URI Path : " + uri.getPath());
Log.e("Check", "Real Path : " + path);
}
}
public String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = getContentResolver().query(contentUri, null, null, null, null);
cursor.moveToFirst();
String document_id = cursor.getString(0);
document_id = document_id.substring(document_id.lastIndexOf(":")+1);
cursor.close();
cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,null
, MediaStore.Images.Media._ID + " = ? ", new String[]{document_id}, null);
cursor.moveToFirst();
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
cursor.close();
return path;
}
@aadeshsethi
Copy link

@cartantino Have you found any solution for it?

@cartantino
Copy link

@cartantino Have you found any solution for it?

Hi @aadeshsethi, yeah I've found another solution.
I've found this library some times ago: https://github.com/HBiSoft/PickiT.
Give it a look, good luck,

Costantino.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment