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: mai
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.
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" />