Android:FileProvider“找不到配置的根目录" [英] Android: FileProvider "Failed to find configured root"

查看:77
本文介绍了Android:FileProvider“找不到配置的根目录"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 FileProvider 通过电子邮件共享 SQL 数据库文件.

I'm trying to use FileProvider to share a SQL database file via email.

错误:

java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.columbiawestengineering.columbiawest/databases/testresults.db

我的代码:

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

Manifest.xml:

Manifest.xml:

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.columbiawestengineering.columbiawest"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
    </provider>

Java.code:

    File goob = this.getDatabasePath("testresults.db");
    Log.d("LOG PRINT SHARE DB", "File goob..? getDatabasePath.. here it is: " + goob.toString());

    Uri contentUri = FileProvider.getUriForFile(this, "com.columbiawestengineering.columbiawest", goob);
    Log.d("LOG PRINT SHARE DB", "contentUri got: here is contentUri: " + contentUri.toString());

此外,goob 的 Logcat 显示了正确的数据库位置:

Also, Logcat for goob shows the correct db location:

....../com.columbiawestengineering.columbiawest D/LOG PRINT SHARE DB: File goob..? getDatabasePath.. here it is: /data/data/com.columbiawestengineering.columbiawest/databases/testresults.db

有什么帮助吗?

从 developer.android,看来 xml files-path... 代表 files/子目录.但这不是文件的存储位置.我不知所措.

From developer.android, it appears that the xml files-path... represents the files/ subdirectory. But that is not where the file is stored. I'm at a loss.

推荐答案

此外,goob 的 Logcat 显示了正确的数据库位置:

Also, Logcat for goob shows the correct db location:

是的,但这不是 指向的地方.给定该数据库路径,等效的 getFilesDir() 将是:

Yes, but that's not where <files-path> points to. Given that database path, the equivalent getFilesDir() would be:

/data/data/com.columbiawestengineering.columbiawest/files

因此,您的数据库不在 getFilesDir() 目录中,这是 使用的目录,这就是为什么 FileProvider 不高兴.FileProvider 不支持从数据库目录共享内容.

Hence, your database is not inside the getFilesDir() directory, which is what <files-path> uses, which is why FileProvider is not happy. FileProvider does not support sharing content from the database directory.

这篇关于Android:FileProvider“找不到配置的根目录"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆