Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Facebook content provider authority

I'm developing an app with (at least) two flavors having different package names - therefore actually two different apps as far as the android system is concerned. The app uses Facebook sharing, so I have the provider declared in the manifest:

<provider android:authorities="com.facebook.app.FacebookContentProvider{app id here}"
            android:name="com.facebook.FacebookContentProvider"
            android:exported="true"/>

This is done according to Facebook's instructions: https://developers.facebook.com/docs/sharing/android

This works fine with one app, but trying to install the second app on the same device fails with the error INSTALL_FAILED_CONFLICTING_PROVIDER. This is the only provider defined in the manifest so I'm pretty sure it's the problem. If I change the provider string to be something different it crashes when attempting to open a Facebook share dialog.

I've seen claims that it's possible to use the same Facebook app in multiple android apps, but can't find anything in Facebook's documentation about it. Has anybody done this, and how did you get around the provider authority problem? Thanks.

like image 391
nasch Avatar asked Jun 12 '15 16:06

nasch


People also ask

What is content provider authority?

Because this recommendation is also true for Android package names, you can define your provider authority as an extension of the name of the package containing the provider. For example, if your Android package name is com. example. <appname> , you should give your provider the authority com.

What is content provider in Android?

A content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object.

Is Facebook a content provider?

The Facebook CEO said in August that the social-networking giant had no ambitions of being a content provider, insisting that Facebook is "a tech company, not a media company." On Wednesday, he appeared to retreat a bit on that statement, painting a slightly different portrait of his company during a Live video chat ...


4 Answers

One of the possible solutions I have found is the one described here

http://gradlewhy.ghost.io/overcoming-install-failed-conflicting-provider/

I am already using this for (debug/release variants) android.support.v4.content.FileProvider and as far I have tested also works for com.facebook.app.FacebookContentProvider.

Just add into apps build.gradle

    debug {
        applicationIdSuffix '.debug'
        versionNameSuffix '-DEBUG'

        resValue "string", "fb_provider_id", "com.facebook.app.FacebookContentProvider{app_id_1}"
    }

    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        resValue "string", "fb_provider_id", "com.facebook.app.FacebookContentProvider{app_id_2}"
    }

and then in the AndroidManifest

<provider android:authorities="@string/fb_provider_id"
        android:name="com.facebook.FacebookContentProvider"
        android:exported="true"/>
like image 180
borko Avatar answered Oct 22 '22 01:10

borko


I was able to solve this by having separate manifests for my debug and release flavors and in my debug flavor manifest, I added the snippet for the provider but set the exported value to false. In my release flavor manifest, I have the original provider snippet with exported set to true.

After I did this, I no longer got the INSTALL_FAILED_CONFLICTING_PROVIDER error.

<provider android:authorities="com.facebook.app.FacebookContentProvider{app id here}"
            android:name="com.facebook.FacebookContentProvider"
            android:exported="false"/>
like image 39
jkunzika Avatar answered Oct 22 '22 02:10

jkunzika


<provider android:authorities="com.facebook.app.FacebookContentProvider{app id here}"
            android:name="com.facebook.FacebookContentProvider"
            android:exported="false"/>

exported can be "true"

like image 3
Arkady Sladkoff Avatar answered Oct 22 '22 01:10

Arkady Sladkoff


If your have one project and multiple flavors(means: multiple apps with minor tweaks) like me, you can

1.create multiple facebook app (from https://developers.facebook.com/apps/)

2.add codes for correspoding flavor

3.add facebook_app_id string value in the corresponding flavor's folder.

Example:

app/build.gradle

...
flavorDimensions "regular"

productFlavors {
    flavour_name {
        dimension "regular"
        resValue "string", "authority", "com.facebook.app.FacebookContentProvider123456789"
    }

app/src/main/AndroidManifest.xml

  <meta-data android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"/>

<provider android:authorities="@string/authority"
        android:name="com.facebook.FacebookContentProvider"
        android:exported="true" />

app/src/flavour_name/res/values/string.xml

<string name="facebook_app_id" translatable="false">123456789</string>
like image 2
touhid udoy Avatar answered Oct 22 '22 01:10

touhid udoy