mardi 30 juin 2020

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?

Aucun commentaire:

Enregistrer un commentaire