Skip to content

Instantly share code, notes, and snippets.

@openrijal
Last active April 21, 2021 03:26
Show Gist options
  • Save openrijal/5494970 to your computer and use it in GitHub Desktop.
Save openrijal/5494970 to your computer and use it in GitHub Desktop.
Get Path from URI in Android.
/*
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;
}
@abdullah-2019
Copy link

DATA is deprecated!

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