【发布时间】:2017-05-09 02:03:33
【问题描述】:
我在尝试使用 FileProvider 时遇到此异常:
Java.Lang.IllegalArgumentException: Unable to find configured root for content://com.abc/Android/data/com.abc/files/345345345.pdf Java.Lang.IllegalArgumentException
我猜我的 file_paths.xml 用错误的路径配置了 FileProvider。我的代码:
file_paths.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path path="." name="." />
<files-path path="com.abc/Android/data/com.abc/files/" name="files" />
</paths>
androidManifest.xml
<application android:label="@string/AppName" android:icon="@drawable/ic_launcher">
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.abc" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
</provider>
</application>
我应该在file_paths.xml 中输入path 和name 中的哪些值,以使用内容URI:content://com.abc/Android/data/com.abc/files/345345345.pdf 公开文件?
我创建 URI 的代码:
File newFile = new File (Application.Context.FilesDir.AbsolutePath, filename);
Android.Net.Uri androidContentUri = FileProvider.GetUriForFile (Application.Context, Application.Context.PackageName, newFile);
System.Uri systemContentUri = SystemUri (androidContentUri);
return systemContentUri;
【问题讨论】:
标签: android xamarin xamarin.android android-fileprovider