Android File Provider Illegal Argument Exception

2019-04-19 03:11发布

问题:

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

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

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>

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>

and Java code:

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

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)

回答1:

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