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

Mic*_*hał 14 android android-image android-xml android-file android-fileprovider

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

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

我的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>
Run Code Online (Sandbox Code Playgroud)

我的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>
Run Code Online (Sandbox Code Playgroud)

和Java代码:

File externalFilesDirectory = this.getExternalFilesDir(null);
File imageFile = File.createTempFile(
        imageFileName,
        ".jpg",
        externalFilesDirectory
);
Uri photoURI = FileProvider.getUriForFile(this, "com.example", imageFile);
Run Code Online (Sandbox Code Playgroud)

最后一行给出了例外.我在这里错过了什么?我已经关注了官方Android开发网站的教程(https://developer.android.com/training/camera/photobasics.html)

Mic*_*hał 19

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

  • 有时订购事宜.我已经在我的权限名称中使用了.provider并且接受了它,只是如果我有多个提供者,那么应该首先声明文件提供者. (2认同)