GrzegDev
GrzegDev

Reputation: 135

how to set up android:authorities for testing?

I have the following source code:

FileProvider.getUriForFile(activity, activity.getPackageName() + ".file", file);

and the following in the Manifest.xml:

<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="app.domain.app-name.file"
    ...
</provider>

which works correctly when the app is running. However, when running instrumented tests, activity.getPackageName() returns my app's package name with ".test" appended to it causing the following exception:

java.lang.IllegalArgumentException: 
Couldn't find meta-data for provider with authority app.domain.app-name.test.file

What is the correct setup that works in both cases?

Upvotes: 1

Views: 779

Answers (1)

Saurabh Thorat
Saurabh Thorat

Reputation: 20684

Change your android:authorities to this:

android:authorities="${applicationId}.file"

Upvotes: 1

Related Questions