Android Facebook sdk 3.5 share dialog

12,196

Solution 1

This is what Facebook recommends. I've just copied the code examples from this link where it is also explained how to handle the uiHelper instance.

If you don't care about the results of the dialog it might be ok not to use the uiHelper.

Using the static method to check whether the dialog can be presented is prudent because it only initializes the builder and creates the dialog if it really is possible to present it.

if (FacebookDialog.canPresentShareDialog(getApplicationContext(),
FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
    // Publish the post using the Share Dialog
    FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
            .setLink("https://developers.facebook.com/android")
            .build();
    uiHelper.trackPendingDialogCall(shareDialog.present());

} else {
    // Fallback. For example, publish the post using the Feed Dialog
    publishFeedDialog();
}

And this is the feed dialog fallback:

private void publishFeedDialog() {
    Bundle params = new Bundle();
    params.putString("name", "Facebook SDK for Android");
    params.putString("caption", "Build great social apps and get more installs.");
    params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
    params.putString("link", "https://developers.facebook.com/android");
    params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");

    WebDialog feedDialog = (
            new WebDialog.FeedDialogBuilder(getActivity(),
                    Session.getActiveSession(),
                    params)).build();
    feedDialog.show();
}

Solution 2

I had this exact problem, it turned out I forgot to add <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/> before the </application> tag in my AndroidManifest.xml.

Share:
12,196
NoobMe
Author by

NoobMe

im a newbie and learning trying to help those who are below me so the cycle continues :) thats why i hope pro's can help me learn more

Updated on June 04, 2022

Comments

  • NoobMe
    NoobMe almost 2 years

    hi i am implementing the facebook share dialog for android sdk 3.5 however i am not getting any success im following the guides..

    FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(MyClass.this)
                                .setApplicationName("App Name")
                                .setName("Name")
                                .setLink("mylink")
                                .build();
    

    i put this inside my on touch method there are no errors appearing but whenever i click the button.. nothing appears also~

    is the MyClass.this wrong? thanks for reply~