12

In the new Fb SDK 4.0 for Android you can register a callback for the LoginButton according to the docs. https://developers.facebook.com/docs/facebook-login/android/v2.3

The question is is this possible for the AppInviteDialog as well? Or is there any other way to identify if the App-Invite was successful or not?

1 Answers1

15

Yes, this is possible.

public static void openDialogInvite(final Activity activity)
{
    String appLinkUrl, previewImageUrl;

    appLinkUrl = "your app link url";
    previewImageUrl = "https://www.example.com/my_invite_image.jpg";

    if (AppInviteDialog.canShow())
    {
        AppInviteContent content = new AppInviteContent.Builder()
                .setApplinkUrl(appLinkUrl)
                .setPreviewImageUrl(previewImageUrl)
                .build();

        AppInviteDialog appInviteDialog = new AppInviteDialog(activity);
        CallbackManager sCallbackManager = CallbackManager.Factory.create();
        appInviteDialog.registerCallback(sCallbackManager, new FacebookCallback<AppInviteDialog.Result>()
        {
            @Override
            public void onSuccess(AppInviteDialog.Result result)
            {
            }

            @Override
            public void onCancel()
            {
            }

            @Override
            public void onError(FacebookException e)
            {
            }
        });

        appInviteDialog.show(content);
    }
}
einverne
  • 6,454
  • 6
  • 45
  • 91
Karim Varela
  • 7,562
  • 10
  • 53
  • 78
  • 2
    Do you know how to get the selected friends? As far as I know, this version doesn't pass their id in the AppInviteDialog.Result. – Juampa Apr 14 '15 at 22:49
  • @Proverbio You are correct. Afaik, FB will no longer give us the selected friends because they don't want developers to incentivize inviting friends. – Karim Varela Apr 15 '15 at 04:28
  • 6
    Thank you that worked like a charm, I also forgot to add onActivityResult() with the callback in it so that should be considered as well if somebody has the same issue. – Philipp R. Steiner Apr 16 '15 at 08:43
  • 4
    Does anyone else get fail after you press invite? The applink is correct, it just doesn't send the invite. – DDsix Apr 30 '15 at 11:22
  • I'm experiencing the same issue as DDsix. Everything in the client indicates that the invite was a success, including the Callback, however the user never receives the invite on Facebook. – Zambotron Jul 23 '15 at 17:50
  • 8
    Also need to provide onActivityResult implementation to get callback. public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); callbackManager.onActivityResult(requestCode, resultCode, data); } – shaby Aug 02 '16 at 09:19
  • As @shaby mention, this is essential to the answer. here is the snippet http://stackoverflow.com/a/42876956/1284177 – Moxor Apr 10 '17 at 15:26