简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM