As Error:Failed to find configured root that contains /storage/emulated/0/xxx/xxx/xxx.png

occurrence scenario:

refers to a third-party package, and when its photo function is activated, it directly flashes back

java.lang.IllegalArgumentException: Failed to find configured root that contains 
/storage/emulated/0/PictureSelector/CameraImage/PictureSelector_20190704_135543.png
        at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:739)
        at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:418)
        at com.luck.picture.lib.PictureSelectorActivity.parUri(PictureSelectorActivity.java:444)
        at com.luck.picture.lib.PictureSelectorActivity.startOpenCamera(PictureSelectorActivity.java:378)
        at com.luck.picture.lib.PictureSelectorActivity.startCamera(PictureSelectorActivity.java:353)
        at com.luck.picture.lib.PictureSelectorActivity$10.onNext(PictureSelectorActivity.java:753)
        at com.luck.picture.lib.PictureSelectorActivity$10.onNext(PictureSelectorActivity.java:744)

search data found that it was related to the android system version of the mobile phone, my mobile phone is android 9.0, and I have some requirements on the management rights of the file

first step, specify a FileProvider. Declare an entry

in the androidmanifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
        ...>
		 <provider
            android:name=".app.MyFileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"
                tools:replace="android:resource" />
        </provider>
        ...
    </application>
</manifest>

second step, need in project res-> Add: provider_paths.xml

external-path specifies the directory you want to share. The name can be arbitrary but try to avoid the same as above. Path specifies the desired directory

then add the following at the bottom:

<?xml version="1.0" encoding="utf-8"?>
<paths>
.........
	<external-path
        name="picture_selector"
        path="PictureSelector/" />
</paths>

Read More: