我正在尝试从图库中选择的图像的Uri中获取真实路径,但是这个函数总是返回null值:
//Convert the image URI to the direct file system path of the image file
public String getRealPathFromURI(Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Images.Media.DATA };
cursor = getActivity().getContentResolver().query(contentUri, proj, null, null, null);
cursor.moveToFirst();
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
ACTION_PICK
是有效的,但是ACTION_GET_CONTENT
似乎仍然没有传递文件路径。=/ - Budius