Android 文件提供程序非法参数异常

标签 android android-xml android-image android-file android-fileprovider

我正在使用文件提供程序将照片保存到给定的目的地。 我得到:

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/

相关文章:

android - 如何在自定义应用程序中使用来自 Android Stock Calendar 的 View (月、日、周)

java - 操作图像的内存有效方法?

android - 如何查找包含特定图像/ Logo 的图像

Android 图像缓存/Web/内存库

android - 旁遮普文字在手机上无法正确显示

java - Android 实时推送到网站

android - 在 Android 中的 ProgressDialog/AlertDialog 上禁用背景暗淡

android - android中不流畅,滞后的动画

android - 菜单项文本未显示在 BottomAppBar 中

java - 我可以使用我的 Java 代码来开发 Android 应用程序吗?