E-Kami
E-Kami

Reputation: 2659

Facebook android sdk 4.0.1 - callbacks not called

I'm currently writing some tests where I "mock" the FacebookActivity by my own FakeFacebookActivity which only purpose is to shutdown itself and set a result code. So here, instead of using: LoginManager.getInstance().logInWithReadPermissions(activity, Arrays.asList("email")); which launch the real facebook login page, I do the following instead:

Intent fakeFbIntent = new Intent(activity, FakeFbLoginActivity.class);
fakeFbIntent.putExtra("resultCode", 0);
activity.startActivityForResult(fakeFbIntent, 64206);

Both methods, at the end of their process fall in the onActivityResult() of the calling activity.Therefore for the facebook callbacks to be called (those in FacebookCallback<LoginResult>) I write my onActivityResult() this way:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        CallbackManager.Factory.create().getCallBackManager().onActivityResult(requestCode, resultCode, data);
}

The problem here is that these callbacks are being called when I use LoginManager.getInstance().logInWithReadPermissions(activity, Arrays.asList("email")); but not with my faked method. What am I missing here? Thank you.

Upvotes: 1

Views: 883

Answers (1)

Gokhan Caglar
Gokhan Caglar

Reputation: 1137

You'd have to make the callback manager route to your FakeActivity, which will then call your callback. You'd need to look at how LoginManager registers it's callback. You'd need to use CallbackManagerImpl. Be aware that CallbackManagerImpl is internal, and can change without notice.

It may be simpler to call your callback directly from your FakeFbLoginActivity, or your onActivityResult.

Upvotes: 1

Related Questions