URGENT Facebook GameRequestDialog not calling callbacks

JoeBonavitaJoeBonavita USMember ✭✭
edited February 2018 in Xamarin.Android

I'm using the Xamarin.Facebook.Android package for this. The dialog displays correctly and the requests go through to the correct recipients but the callbacks never get called. I'm not 100% sure where I'm supposed to get the CallbackManager from.

I've been stuck on this issue for about a week now. It's holding up a release of our app.

I'd greatly appreciate any help.

`
public class FacebookService : IFacebookService
{
public void InviteFriends(FacebookInviteCallbacks facebookInviteCallbacks)
{
if (AppInviteDialog.CanShow())
{
var activity = Xamarin.Forms.Forms.Context as Activity;
var content = new GameRequestContent.Builder().
SetTitle("Check out this game").
SetMessage("Check out this game I play!").
Build() as GameRequestContent;

        var dialog = new GameRequestDialog(activity);

        dialog.RegisterCallback(CallbackManagerFactory.Create(), new MyFacebookCallback(facebookInviteCallbacks));
        dialog.Show(content);                

    }
}       

}

public class MyFacebookCallback : Java.Lang.Object, IFacebookCallback
{
private FacebookInviteCallbacks facebookInviteCallbacks;

public ImcFacebookCallback(FacebookInviteCallbacks facebookInviteCallbacks)
{
    this.facebookInviteCallbacks = facebookInviteCallbacks;
}

public void OnCancel()
{
    System.Diagnostics.Debug.WriteLine("Cancelled sending invite");
}

public void OnError(FacebookException error)
{
    facebookInviteCallbacks.FailedCallback(error.Message);
}

public void OnSuccess(Java.Lang.Object result)
{
    System.Diagnostics.Debug.WriteLine(result);
}

}`

Best Answer

  • JoeBonavitaJoeBonavita US ✭✭
    Accepted Answer

    After a lot of digging and trial and error I finally got this working.

    In my FacebookService class I added:

     public static ICallbackManager callbackManager;
    

    In the Invitefriends method, in the if statement I changed this:

    dialog.RegisterCallback(CallbackManagerFactory.Create(), new MyFacebookCallback(facebookInviteCallbacks));
    

    to

     callbackManager = CallbackManagerFactory.Create();
     dialog.RegisterCallback(callbackManager, new ImcFacebookCallback(facebookInviteCallbacks));
    

    In the MainActivity I added the following override.

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);                        
    
        Services.FacebookService.callbackManager.OnActivityResult(requestCode, (int)resultCode, data);
    }
    

    That's all it took. I wish the package would have been better documented.

Answers

  • JoeBonavitaJoeBonavita USMember ✭✭

    Anyone??? I'd be very surprised if no one else is using this.

  • JoeBonavitaJoeBonavita USMember ✭✭
    Accepted Answer

    After a lot of digging and trial and error I finally got this working.

    In my FacebookService class I added:

     public static ICallbackManager callbackManager;
    

    In the Invitefriends method, in the if statement I changed this:

    dialog.RegisterCallback(CallbackManagerFactory.Create(), new MyFacebookCallback(facebookInviteCallbacks));
    

    to

     callbackManager = CallbackManagerFactory.Create();
     dialog.RegisterCallback(callbackManager, new ImcFacebookCallback(facebookInviteCallbacks));
    

    In the MainActivity I added the following override.

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);                        
    
        Services.FacebookService.callbackManager.OnActivityResult(requestCode, (int)resultCode, data);
    }
    

    That's all it took. I wish the package would have been better documented.

Sign In or Register to comment.