14

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)

Michał
  • 655
  • 6
  • 19

2 Answers2

19

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

Michał
  • 655
  • 6
  • 19
  • Can you provide link to any document to require FileProvider authority name must end with ".fileprovider"? – anticafe May 24 '17 at 03:37
  • https://developer.android.com/reference/android/support/v4/content/FileProvider.html#ProviderDefinition – Arst Jun 26 '17 at 03:31
  • This might have been a bug in android that they later fixed, coz I am using an Authority without the `.fileprovider` extension. It works fine. – Henry Sep 11 '17 at 14:46
  • 3
    sometimes ordering matters. I have used .provider in my authority name & its accepted, only the fact that if I am having more than 1 provider, then file provider should be declared first. – Ashish John Oct 25 '17 at 12:02
1

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

pramod_m
  • 184
  • 1
  • 9