FileProvider.GetUriForFile()抛出异常。找不到已配置的根

时间:2016-01-07 16:40:32

标签: android xamarin

这是我尝试创建ContentUri的代码,因此我可以调用pdf查看器。

〜提供者哪个IS在<Application><authority>内与包名

绝对匹配
<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="com.company.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">

    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths"/>
</provider>

~xml / filepaths.xml

<?xml version="1.0" encoding="UTF-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="assets" path="Library/OfflineAssets/"/>
</paths> 

〜.cs我有异常

var dir = "/data/data/com.tripleplay_services.triplesport/files/../Library/OfflineAssets/xamarin_documentation1_v1.pdf";
var newFile = new File(dir);
if(newFile.Exists ()) {
    var contentUri = FileProvider.GetUriForFile(Context, "com.company.fileprovider", newFile);
}

BANG!

无法找到包含/data/data/com.company/Library/OfflineAssets/xamarin_documentation1_v1.pdf

的已配置根目录

我正在做这本书。我被困住了,无法继续。

Here is where the exception is thrown。我不知道mRoots.entrySet()中的内容是什么导致应用程序崩溃。

2 个答案:

答案 0 :(得分:0)

因此,在阅读源代码后,我发现提供商正在尝试将/data/data/com.package/files/Library/OfflineAssets与/data/data/com.package/../Library/OfflineAssets(/ p>

所以基本上我对android的文件目录的理解是不正确的。

确保在<files-path>路径属性中的data / data / com.package / files /匹配之后,您保存文件的目录是什么。

〜更新了<files-path>

<files-path name="assets" path="../Library/OfflineAssets/" />

答案 1 :(得分:0)

我有一个类似的问题(在我的应用程序中我试图调用相机而不是PDF查看器)但后来我发现我的代码中有一个拼写错误。 输入错误是在AndroidManifest.xml中,正好在#34;权限&#34;行中的标记中。

对我来说,

android:authorities="com.stackoverflow.test.camerawithfileprovider.fileprovider"

不起作用(当我调用相机实例时,应用程序崩溃)但如果我删除&#34;文件&#34;并将该字符串替换为:

android:authorities="com.stackoverflow.test.camerawithfileprovider.provider"

我的应用程序运行流畅(应用程序拍摄照片,存储它,并在客户端应用程序中返回活动预览)。

您的应用也有同样的问题吗?

相关问题