Last active
April 21, 2021 03:26
-
-
Save openrijal/5494970 to your computer and use it in GitHub Desktop.
Get Path from URI in Android.
This file contains hidden or 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
/* | |
Input: URI -- something like content://com.example.app.provider/table2/dataset1 | |
Output: PATH -- something like /sdcard/DCIM/123242-image.jpg | |
*/ | |
public String convertMediaUriToPath(Uri uri) { | |
String [] proj={MediaStore.Images.Media.DATA}; | |
Cursor cursor = getContentResolver().query(uri, proj, null, null, null); | |
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); | |
cursor.moveToFirst(); | |
String path = cursor.getString(column_index); | |
cursor.close(); | |
return path; | |
} |
DATA is deprecated!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I suggest u all to use a custom image or file picker for getting the path of file , as all this work is already done inside the library and all the errors are handled too.
For images u can checkout : pix