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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DATA is deprecated!