我正在使用文件提供程序将照片保存到给定的目的地。 我得到:
java.lang.IllegalArgumentException:缺少 android.support.FILE_PROVIDER_PATHS 元数据 在尝试打开 Activity 以从相机捕获图像时。
我的 manifest.xml 文件:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/paths" />
</provider>
我的 paths.xml 文件:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="content" path="Android/data/com.my_package_name/files/" />
</paths>
和Java代码:
File externalFilesDirectory = this.getExternalFilesDir(null);
File imageFile = File.createTempFile(
imageFileName,
".jpg",
externalFilesDirectory
);
Uri photoURI = FileProvider.getUriForFile(this, "com.example", imageFile);
最后一行给出了异常。 我在这里错过了什么?我遵循了官方 Android 开发网站 ( https://developer.android.com/training/camera/photobasics.html ) 的教程
最佳答案
我找到了解决方案。问题是我的权限名称没有以“.fileprovider”结尾。固定。
关于Android 文件提供程序非法参数异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38978198/