Search code examples
androidsharephotofacebook-sdk-4.x

I can't share images using the Share dialog


Ok guys I don't know what I am doing wrong and I am losing my mind over this issue.I just started using Facebook Android SDK and I have no Idea what I am doing wrong.

I am developing a app which needs to share picture on Facebook.First I tried sharing status.It worked just fine.

Then I tried sharing photos according to the information on the documentations.Nothing happened.

This is my manifest.

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

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

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

The App id is correct.And I have set up a ContentProvider in my AndroidManifest.xml.

And this is my Java.

    Bitmap image2 = BitmapFactory.decodeResource(getResources(), R.drawable.android);
    SharePhoto photo = new SharePhoto.Builder().setBitmap(image2).build();
    SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();
    ShareDialog dialog = new ShareDialog(MainActivity.this);
    dialog.show(content);

Please help.


Solution

  • After much pondering I finally solved this problem.For image share to work properly one should keep two things in mind.

    1.Set up ContentProvider in your AndroidManifest.xml.

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

    where 1501607393****** is your app code.

    2.Install the official Facebook app in the device before testing yourapp.