Skip to content

Instantly share code, notes, and snippets.

@Kun-Yao-Lin
Created January 31, 2016 05:44
Show Gist options
  • Save Kun-Yao-Lin/3f88a4b019ab44ec3ad7 to your computer and use it in GitHub Desktop.
Save Kun-Yao-Lin/3f88a4b019ab44ec3ad7 to your computer and use it in GitHub Desktop.
getFilePathFromUri
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