【问题标题】:FileProvider error "Failed to find configured root that contains /data/data/sawbodeployer.entm.illinois.edu ..."FileProvider 错误“未能找到包含 /data/data/sawbodeployer.entm.illinois.edu ... 的已配置根目录”
【发布时间】:2017-05-29 17:30:10
【问题描述】:

我通过 android 下载管理器下载视频并想分享这个视频,我通过 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>

并在文件 path.xml 中添加:

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

并使用此提供程序:

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);

但我得到错误:

java.lang.IllegalArgumentException:未能找到包含 /data/data/sawbodeployer.entm.illinois.edu/files/AKA1_Fante_Ghana_HandWashing_Final.3gp 的已配置根目录

它的问题在哪里?

【问题讨论】:

    标签: android provider download-manager android-fileprovider


    【解决方案1】:

    替换:

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

    与:

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

    path 用于在根目录下有一些特定的子目录您要从中提供服务时使用。你的文件直接在getFilesDir(),所以你不能使用path

    【讨论】:

    • 你可以使用path="."。
    • @greenapps:是的,虽然它不会改变结果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多