我有这条路径的文件:
file:/storage/emulated/0/iWallet/photos/JPEG_20180119040510_972640968.jpg
我想将其转换为android.net.Uri
并在此处使用它:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,photoFile.toURI());
startActivityForResult(takePictureIntent, REQUEST_TAKE_CAMIRA);
}
}
答案 0 :(得分:1)
试试这个:
Uri.fromFile(new File("/storage/emulated/0/iWallet/photos/JPEG_20180119040510_972640968.jpg"))
答案 1 :(得分:-1)
我的问题在于文件提供商,所以我解决了这个问题
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(context,
DBConnect.FILEPROVIDER,
photoFile);
URI uri = photoFile.toURI();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_CAMIRA);
}
}