Android文件提供商非法参数异常 [英] Android File Provider Illegal Argument Exception

查看:174
本文介绍了Android文件提供商非法参数异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using file provider to save photo to a given destination. I get:

java.lang.IllegalArgumentException:缺少android.support.FILE_PROVIDER_PATHS元数据 尝试打开活动以从相机捕获图像时.

java.lang.IllegalArgumentException: Missing android.support.FILE_PROVIDER_PATHS meta-data while trying to open activity to capture image from camera.

我的manifest.xml文件:

My manifest.xml file:

<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>

我的path.xml文件:

My paths.xml file:

<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 )

Last line gives the exception. What am I missing here? I've followed tutorial from official Android development site (https://developer.android.com/training/camera/photobasics.html)

推荐答案

我找到了解决方案.问题是我的授权名称没有以".fileprovider"结尾.固定.

I found the solution. The problem was that my authority name didn't end with ".fileprovider". Fixed.

这篇关于Android文件提供商非法参数异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆