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

Posted BandaYung

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了As Error:Failed to find configured root that contains /storage/emulated/0/xxx/xxx/xxx.png相关的知识,希望对你有一定的参考价值。

发生场景:

引用第三方包,启动它的拍照功能的时候直接闪退

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)

查阅资料发现原来是手机android系统版本有关,自己的手机是Andriod 9.0的,对文件的管理权限有所要求

第一步,指定一个FileProvider。在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>

第二步,需要在项目的res->xml下添加:provider_paths.xml

external-path目录下指定想分享的目录,name可以随意但尽量避免跟上面的一样,path指定所需目录

然后在最下面添加如下:

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

以上是关于As Error:Failed to find configured root that contains /storage/emulated/0/xxx/xxx/xxx.png的主要内容,如果未能解决你的问题,请参考以下文章

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

android stdio 编译项目报Error:Failed to find target with hash string 'android-24

vue.js 进行初始化遇到的关于core-js的错误@core-js/modules/es6.array.find-index (ERROR Failed to compile with 164

Error: failed to execute 'C:KeilARMARMCC'的解决办法

Error: failed to execute 'C:KeilARMARMCC'的解决办法

Error response from daemon: driver failed... Error: failed to start containers...