我正在尝试使用 FileProvider 通过电子邮件共享 SQL 数据库文件。
错误:
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>
清单.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.代码:
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 显示了正确的数据库位置:
....../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/ 子目录。但这不是存储文件的位置。我不知所措。