android N 调用相机时报错:FileUriExposedException

解决方法:

1:在AndroidManifest.xml中添加如下代码:

android N 调用相机时报错:FileUriExposedException

2:在res目录下添加xml文件夹,里面新建一个file_paths文件

android N 调用相机时报错:FileUriExposedException

3.file_paths.xml文件内容

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path path="Android/data/com.dz.everyone/" name="files_root" />
    <external-path path="." name="external_storage_root" />
</paths>
4.适配android N:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    intent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(fragment.getContext(), 
            BuildConfig.APPLICATION_ID + ".fileProvider", new File(UPic.FILE_PATH_WITHOUT_NAME, UPic.FILE_NAME)));

} else {
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(UPic.FILE_PATH_WITHOUT_NAME, UPic.FILE_NAME)));

}