Skip to content

Instantly share code, notes, and snippets.

@ixiyang
Created July 31, 2014 02:21
Show Gist options
  • Save ixiyang/4e9c53dd0a05d94809cc to your computer and use it in GitHub Desktop.
Save ixiyang/4e9c53dd0a05d94809cc to your computer and use it in GitHub Desktop.
get file path from uri
public String getPath(Uri uri) {
String siPath;
// 1:MEDIA GALLERY --- query from MediaStore.Images.Media.DATA
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if (cursor != null) {
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
siPath = cursor.getString(column_index);
} else {
siPath = null;
}
if (siPath == null) {
// 2:OI FILE Manager --- call method: uri.getPath()
siPath = uri.getPath();
}
return siPath;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment