Android7.0拍照报错:file:///storage/0/example.jpg exposed beyond app through ClipData.Item.getUri

Android7.0调用相机时出现新的错误:

android.os.FileUriExposedException: file:///storage/emulated/0/**/**/e820cc60-cae5.jpg exposed beyond app through ClipData.Item.getUri()

解决办法:

在Application的onCreat()方法中添加以下代码:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
     StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
     StrictMode.setVmPolicy(builder.build());
     builder.detectFileUriExposure();
}

你可能感兴趣的:(Android7.0拍照报错:file:///storage/0/example.jpg exposed beyond app through ClipData.Item.getUri)