FileProvider error “Failed to find configured root that contains /data/data/sawbodeployer.entm.illinois.edu …”

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 17:36:50

问题


I download video by android download manager and want to share this video, I follow through Manifas

 <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="my.domain"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/paths" />
    </provider>

and in file path.xml add this:

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="video_folder" path="files/"/>
</paths>

and use this provider:

File file = new File(getActivity().getFilesDir() , videoPath);
                Uri uri = FileProvider.getUriForFile(getContext(), "my.domain", file);
                Intent intent = ShareCompat.IntentBuilder.from(getActivity())
                        .setType("video/3gp")
                        .setStream(uri)
                        .setChooserTitle("Choose bar")
                        .createChooserIntent()
                        .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                startActivity(intent);

but I get error :

java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/sawbodeployer.entm.illinois.edu/files/AKA1_Fante_Ghana_HandWashing_Final.3gp

Where is its problem?


回答1:


Replace:

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="video_folder" path="files/"/>
    <files-path name="name" path="path" />
</paths>

with:

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="video_folder" />
</paths>

path is used when there is some specific subdirectory under the root that you want to serve from. Your file is directly in getFilesDir(), and so you cannot use path.



来源:https://stackoverflow.com/questions/44247796/fileprovider-error-failed-to-find-configured-root-that-contains-data-data-sawb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!