1

I am having an error when I run my app when I try to take a picture.

2019-10-30 07:55:18.411 578-578/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.myapplication, PID: 578 java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority fssdfs

this gives me an error and crashes the app when I click the button to take a picture in my app. Please help!

  • Does this answer your question? [Couldn't find meta-data for provider with authority](https://stackoverflow.com/questions/56598480/couldnt-find-meta-data-for-provider-with-authority) – Ricardo A. Oct 30 '19 at 12:11

2 Answers2

1

I think you missed this code to add in your Manifest.XML file so try this, it will may help you.

<meta-data
android:name="android.support.FILE_PROVIDER_PATHS" <-- HERE!!!
android:resource="@xml/provider_paths" />
Twisha Kotecha
  • 1,082
  • 1
  • 4
  • 18
0

The problem you are facing is because the content provider authority you have declared in your manifest is different from the one that is being used at the point you are requesting a URI from the provider.

Common causes are libraries that have hardcoded their own provider authorities and general mismatch of the provider authority string.

To solve these issues, and at the same time satisfy the condition that the provider authority should be unique, you can use the application id as the provider authority or concatenate the application id variable with your string for the provider authority. The solution is elaborated below:

In your manifest, you could use this as your provider:

       <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}"
            android:exported="false"
            android:grantUriPermissions="true"
            tools:replace="android:authorities">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

In your Java code, you can access the provider with the authority below:

Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName(), file);

Alternatively, if you still want more customisation for your authorities, you could as well do this:

   <provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="${applicationId}.my_custom_addition"
        android:exported="false"
        android:grantUriPermissions="true"
        tools:replace="android:authorities">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
    </provider>

You can then reference the authority in code as shown below:

Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName()+".my_custom_addition", file);

The down side to using the second approach is that you always have to remember the exact string for the custom authority.

I will recommend the first approach, although the latter approach is more desirable when you have multiple content providers in your application.

  • 1
    ok, thank you for the help. when we put the tools:replace="android:authorities" the tools has the error, not bounded. "namespace "tools" is not bound" – HUNTER MILLER Nov 04 '19 at 12:34
  • 1
    You have to define the tools namespace in your manifest element like this: ` – Clement Osei Tano Nov 05 '19 at 11:07
  • if (photoFile!=null) { String pathToFile = photoFile.getAbsolutePath(); Uri photoURI = FileProvider.getUriForFile(MainActivity.this, "fssdfs", photoFile); takePic.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); startActivityForResult(takePic, 1); //In progress need fixed } – HUNTER MILLER Nov 06 '19 at 12:35
  • You should do a test run, to verify that. On the FileProvider side, if your authority is defined as "fssdfs", the you not have any issues pertaining to the FileProvider. – Clement Osei Tano Nov 06 '19 at 16:42