Created
July 31, 2014 02:21
-
-
Save ixiyang/4e9c53dd0a05d94809cc to your computer and use it in GitHub Desktop.
get file path from uri
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
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