android中如何把`content://media/external/images/media/Y`转换为`file:///storage/sdcard0/Pictures/X.jpg`?

查询内容解析器,找到文件存储地址

public static String getRealPathFromUri(Context context, Uri contentUri) {
    Cursor cursor = null;
    try {
        String[] proj = { MediaStore.Images.Media.DATA };
        cursor = context.getContentResolver().query(contentUri, proj, 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();
        }
    }
}

你可能感兴趣的:(IT/ANDROID/file)