Created
June 6, 2014 08:19
-
-
Save akexorcist/4a01eec6e5210a779ec2 to your computer and use it in GitHub Desktop.
Get Real Path from URI which choose from intent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This is not working any more
have you figured it out how to make it work?
Hi! This should work only for images.. I am looking for a solution that works for any kind of file, do you know how to do it?
works for me, but i don't know, if it will work on all the devices
@cartantino Have you found any solution for it?
@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
This is not working any more