Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android File Provider Illegal Argument Exception

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)

like image 866
Michał Avatar asked Aug 16 '16 14:08

Michał


2 Answers

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

like image 143
Michał Avatar answered Oct 21 '22 21:10

Michał


Even when you have authorities properly set up to the appId and there is the FileProvider setup , you should ideally delete the caches , i.e. Delete .gradle and .idea folders or probably Invalidate the caches and restart which enables you to redownload the gradle dependencies again and then it worked for me :) Hope this might help someone

like image 44
pramod_m Avatar answered Oct 21 '22 22:10

pramod_m