我正在尝试为共享文件设置fileprovider.我的文件保存在外部存储器中的"AppName"文件夹中(与Android,Movies和Pictures文件夹相同).
这是我的文件提供程序配置:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mydomain.appname.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
Run Code Online (Sandbox Code Playgroud)
和file_paths.xml:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="mypath" path="AppName" />
</paths>
Run Code Online (Sandbox Code Playgroud)
当我尝试访问我的文件时:
Uri fileUri = FileProvider.getUriForFile(activity, "com.mydomain.appname.fileprovider",
new File("/storage/emulated/0/AppName/IMG_20160419_095211.jpg"));
Run Code Online (Sandbox Code Playgroud)
它返回一个错误:java.lang.IllegalArgumentException:无法在android.support.v4.content.FileProvider $ SimplePathStrategy.getUriForFile(FileProvider.java:678)中找到包含/storage/emulated/0/AppName/IMG_20160419_095211.jpg的已配置根目录)在android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:377)
它在我使用像图片或电影这样的内置目录之前工作正常,我的file_paths.xml定义如下:
<external-path name="photos" path="Pictures" />
<external-path name="videos" path="Movies" />
Run Code Online (Sandbox Code Playgroud)
但现在我想将我的文件存储在我自己的文件夹中.我是否错过了使用FileProvider配置的东西?