我想通过电子邮件使用FileProvider共享SQL数据库文件。Android:FileProvider“无法找到配置的根”
错误:
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:
<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());
此外,对于logcat中显示goob正确的DB位置:
....../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 ...代表文件/子目录。但这不是文件存储的地方。我很茫然。
感谢CommonsWare,这就是我害怕......难道还有其他的获取数据库文件的方法?我可以将它打印到一个字符串并通过电子邮件发送字符串,但是我想通过电子邮件发送实际的数据库文件 –
@DanLehto:[''getDatabasePath()''Context'](http://developer.android.com/reference/android/content/Context.html#getDatabasePath(java.lang.String))会返回给你一个'文件对象指向你的数据库。为了达到FileProvider的目的,欢迎您将该文件复制到'getFilesDir()'或'getCacheDir()'。只要确保你的数据库当时没有被使用。或者,我将在接下来的几天内推出[我的'StreamProvider'](https://github.com/commonsguy/cwac-provider)更新,您应该能够将其扩展为支持直接为您的数据库提供服务。 – CommonsWare