uri转file
file = new File(new URI(uri.toString()));
uri转path:
视频uri
private String getPath(Uri uri) {
String[] projection = {MediaStore.Video.Media.DATA};
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
图片uri
private File uri2File(Uri uri) {
File file = null;
String[] proj = { MediaStore.Images.Media.DATA };
Cursor actualimagecursor = getActivity().managedQuery(uri, proj, null,
null, null);
int actual_image_column_index = actualimagecursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
actualimagecursor.moveToFirst();
String img_path = actualimagecursor
.getString(actual_image_column_index);
file = new File(img_path);
return file;
}
- ##### file转URI:
URI uri = file.toURI();
- ##### file转path:
String path = file.getPath()
- ##### path转uri:
Uri uri = Uri.parse(path);
- ##### path转file:
File file = new File(path)