- * 通过Uri返回File文件 * 注意:通过相机的是类似content://media/external/images/media/97596 * 通过相册选择的:file:///storage/sdcard0/DCIM/Camera/IMG_20150423_161955.jpg
String schemeStr = data.getScheme().toString();
String picPath = "";if (schemeStr.compareTo("file") == 0) {
picPath = uri.toString();
picPath = picPath.replace("file://", "");
} else if (schemeStr.compareTo("content") == 0) {
// 4.2.2以后
String[] filePathColumn = { MediaStore.Images.Media.DATA };Cursor cursor = null;
if (fragment != null) {
cursor = fragment.getActivity().getContentResolver()
.query(uri, filePathColumn, null, null, null);
} else {
cursor = activity.getContentResolver().query(uri,
filePathColumn, null, null, null);
}
if (cursor != null && cursor.moveToFirst()) {
int columnIndex = cursor
.getColumnIndex(filePathColumn[0]);
picPath = cursor.getString(columnIndex);
cursor.close();
}
}