Multiple Apps use same content provider

It’s an old question, but I was looking at doing something similar recently. With the Build flavours, its really straight forward now.

Specify the BuildConfigField in the gradle file:

    productFlavors {
    free {
        applicationId "com.example.free"
        buildConfigField 'String', 'AUTHORITY', '"com.example.free.contentprovider"'
    }

    paid {
        applicationId "com.example.paid"
        buildConfigField 'String', 'AUTHORITY', '"com.example.paid.contentprovider"'
    }

Specify the provider authority in the manifest:

    <provider
        android:name=".ContentProvider"
        android:authorities="${applicationId}.contentprovider" />

Set the authority in the provider using the BuildConfigField Variable:

    public static final String AUTHORITY = BuildConfig.AUTHORITY

Leave a Comment