Skip to content

Instantly share code, notes, and snippets.

@vicky7230
Forked from WrathChaos/android-real-path-uri.md
Last active August 20, 2018 06:27
Show Gist options
  • Save vicky7230/4fd3ae22dffb25c0960c7166b09eba9f to your computer and use it in GitHub Desktop.
Save vicky7230/4fd3ae22dffb25c0960c7166b09eba9f to your computer and use it in GitHub Desktop.
Android: How to get Real Path from Uri?
private String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Images.Media.DATA };
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} catch (Exception e) {
Log.e(TAG, "getRealPathFromURI Exception : " + e.toString());
return "";
} finally {
if (cursor != null) {
cursor.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment