拍照代码如下
Uri imageUri = null;
String fileName = null;
Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
REQUEST_CODE = TAKE_PICTURE;
fileName = "image.jpg";
imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), fileName));
//指定照片保存路径(SD卡),image.jpg为一个临时文件,每次拍照后这个图片都会被替换
openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(openCameraIntent, REQUEST_CODE);
报错:
android.os.FileUriExposedException: file:///storage/emulated/0/image.jpg exposed beyond app through ClipData.Item.getUri()
解决方式 , 现在做的是忽略这个错误 , 暂时file 路径在 7.0中限制的 , 在 application 的 oncreate 方法中添加
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
builder.detectFileUriExposure();