Alex
Alex

Reputation: 11

Android - Facebook SDK 4.0.0 - ShareDialog doesn't show when image sharing

I got a problem with using facebook SDK for sharing an image. I created a button which invoke native facebook app sharing dialog. But unfortunately, it doesn't show up. And the error message on DDMS:

"Failed to find provider info for com.facebook.app.FacebookContentProvider798741073537656"

Please help to give some hint. Thank you!

protected void onCreate(Bundle savedInstanceState) {
    FacebookSdk.sdkInitialize(getApplicationContext());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btn_share = (Button) findViewById(R.id.btn_share);
    shareDialog = new ShareDialog(MainActivity.this);

    btn_share.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Bitmap image = BitmapFactory.decodeFile(path);
            SharePhoto photo = new SharePhoto.Builder().setBitmap(image).build();
            SharePhotoContent content  = new SharePhotoContent.Builder().addPhoto(photo).build();
            shareDialog.show(content);
        }
    });
}

Upvotes: 1

Views: 1673

Answers (5)

r3dm4n
r3dm4n

Reputation: 1215

I've tested this on Glide v4.+

Glide.with(this)
            .asBitmap()
            .load(YOUR_IMAGE_URL).into(new SimpleTarget<Bitmap>() {
        @Override
        public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {

            SharePhoto sharePhoto1 = new SharePhoto.Builder()
                    .setBitmap(resource)
                    .build();

            ShareContent shareContent = new ShareMediaContent.Builder()
                    .addMedium(sharePhoto1)
                    .build();

            new ShareDialog(getActivity()).show(shareContent, ShareDialog.Mode.AUTOMATIC);
        }
    });

Code above will not work unless you add this in Manifest.xml:

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

Documentation: https://developers.facebook.com/docs/sharing/android

Upvotes: 0

Kennethz3
Kennethz3

Reputation: 689

I spent hours trying to figure out the problem. In my case the provider tag was outside the application tag in AndroidManifest.xml. Make sure you include the provider within the Application not outside hope this helps :)

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

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

    <activity
        android:name="com.facebook.FacebookActivity"
        android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        tools:replace="android:theme"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"
        android:label="@string/app_name" />

    <provider android:authorities="com.facebook.app.FacebookContentProvider1533172037423618"
        android:name="com.facebook.FacebookContentProvider"
        android:exported="true" />

</application>

Upvotes: 1

Antzi
Antzi

Reputation: 13414

For me the issue was that the <provider> must be inside the <application> tags of the AndroidManifest.xml sdk

Upvotes: 0

Birat Bade Shrestha
Birat Bade Shrestha

Reputation: 870

First be sure you have mentioned the content provider in the AndroidManifest.xml

<provider android:authorities="com.facebook.app.FacebookContentProvider1234"
  android:name="com.facebook.FacebookContentProvider"
  android:exported="true"/>

1234 is you app id.

Second use a real device to test your application.And make sure you have installed the official Facebook application in your device.

Upvotes: 0

Radu Cojocaru
Radu Cojocaru

Reputation: 27

I had a similar issue and what I was missing was the provider tag in AndroidManifest.xml. From the Facebook documentation (https://developers.facebook.com/docs/sharing/android#photos):

You also need to set up a ContentProvider in your AndroidManifest.xml where {APP_ID} is your app ID:

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

Upvotes: 1

Related Questions