Skip to content

Instantly share code, notes, and snippets.

@Collosteam
Created October 23, 2014 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Collosteam/ffcdfcf6cf10f737a280 to your computer and use it in GitHub Desktop.
Save Collosteam/ffcdfcf6cf10f737a280 to your computer and use it in GitHub Desktop.
Android Uri to File new API (11+)
public String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] projection = {MediaStore.Images.Media.DATA};
cursor = context.getContentResolver().query(contentUri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment