2018-03-13

        解决调用系统拍照targetSdkVersion>=24的FileUriExposedException

1.通过Application解决

    File file = new File(fileName);

    Uri uri = Uri.fromFile(file)

Application 中onCreate()添加

// android 7.0系统解决拍照的问题

StrictMode.VmPolicy.Builder builder =new StrictMode.VmPolicy.Builder();

StrictMode.setVmPolicy(builder.build());

builder.detectFileUriExposure();

2.通过判断targetSdkVersion版本,,大于等于24,则通过FileProvider来实现

(1)

if (Build.VERSION.SDK_INT >=24) {

   imageUri = FileProvider.getUriForFile(this,"com.zzh.onresumedemo.PhotoActivity",outputImage);

}else {

   imageUri = Uri.fromFile(outputImage);

}

(2)

AndroidManifest中设置provider

    android:authorities="com.zzh.onresumedemo.PhotoActivity"


    android:name="android.support.v4.content.FileProvider"

    android:exported="false"

    android:grantUriPermissions="true">

     android:name="android.support.FILE_PROVIDER_PATHS"

     android:resource="@xml/file_paths">

划线部分authorities填写摄像头调用的activity

(3)

file_pahts 再res中建立xml文件夹,new file_paths.xml,填写

   

你可能感兴趣的:(2018-03-13)