gpt4 book ai didi

安卓 : FileProvider on custom external storage folder

转载 作者:可可西里 更新时间:2023-11-01 18:55:04 25 4
gpt4 key购买 nike

我正在尝试设置一个文件提供程序来共享文件。我的文件保存在外部存储的“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>

和 file_paths.xml :

<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="mypath" path="AppName" />
</paths>

当我尝试访问我的文件时:

Uri fileUri = FileProvider.getUriForFile(activity, "com.mydomain.appname.fileprovider",
new File("/storage/emulated/0/AppName/IMG_20160419_095211.jpg"));

它返回一个错误:java.lang.IllegalArgumentException:找不到包含/storage/emulated/0/AppName/IMG_20160419_095211.jpg 的已配置根目录 在 android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:678) 在 android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:377)

在我使用内置目录(如图片或电影)之前它工作正常,我的 file_paths.xml 定义如下:

<external-path name="photos" path="Pictures" />
<external-path name="videos" path="Movies" />

但现在我想将我的文件存储在我自己的文件夹中。我是否遗漏了 FileProvider 配置的某些内容?

最佳答案

<files-path name="name" path="path" />  

Represents files in the files/ subdirectory of your app's internal storage area. This subdirectory is the same as the value returned by Context.getFilesDir().

<external-path name="name" path="path" />

Represents files in the root of the external storage area. The root path of this subdirectory is the same as the value returned by Environment.getExternalStorageDirectory().

<external-files-path name="name" path="path" />

Represents files in the root of your app's external storage area. The root path of this subdirectory is the same as the value returned by Context#getExternalFilesDir(String) Context.getExternalFilesDir(null).

更多详情请查看Android's doc of FileProvider .一些配置如下图,com.view.asim.enterprise 是我的包名。 enter image description here

关于安卓 : FileProvider on custom external storage folder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37074872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com