Created
January 31, 2016 05:44
-
-
Save Kun-Yao-Lin/3f88a4b019ab44ec3ad7 to your computer and use it in GitHub Desktop.
getFilePathFromUri
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 static String getImagePath(Context context, Uri uri){ | |
| Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); | |
| cursor.moveToFirst(); | |
| String document_id = cursor.getString(0); | |
| document_id = document_id.substring(document_id.lastIndexOf(":")+1); | |
| cursor.close(); | |
| cursor = context.getContentResolver().query( | |
| android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, | |
| null, MediaStore.Images.Media._ID + " = ? ", new String[]{document_id}, null); | |
| cursor.moveToFirst(); | |
| String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)); | |
| cursor.close(); | |
| return path; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment