简体   繁体   English

Facebook Android SDK 4.0.1-未调用回调

[英]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. 我目前正在编写一些测试,在这些测试中,我通过自己的FakeFacebookActivity “模拟” FacebookActivity ,其唯一目的是关闭自身并设置结果代码。 So here, instead of using: LoginManager.getInstance().logInWithReadPermissions(activity, Arrays.asList("email")); 因此,这里而不是使用: LoginManager.getInstance().logInWithReadPermissions(activity, Arrays.asList("email")); which launch the real facebook login page, I do the following instead: 哪个启动了真正的Facebook登录页面,我改为执行以下操作:

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: 这两种方法在其处理过程的最后都属于调用活动的onActivityResult() 。因此,要调用facebook回调(在FacebookCallback<LoginResult>那些),我以这种方式编写onActivityResult()

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")); 这里的问题是,当我使用LoginManager.getInstance().logInWithReadPermissions(activity, Arrays.asList("email"));时,将调用这些回调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. 您必须将回调管理器路由到您的FakeActivity,然后它将调用您的回调。 You'd need to look at how LoginManager registers it's callback. 您需要查看LoginManager如何注册其回调。 You'd need to use CallbackManagerImpl. 您需要使用CallbackManagerImpl。 Be aware that CallbackManagerImpl is internal, and can change without notice. 请注意,CallbackManagerImpl是内部的,并且可以随时更改,恕不另行通知。

It may be simpler to call your callback directly from your FakeFbLoginActivity, or your onActivityResult. 直接从FakeFbLoginActivity或onActivityResult调用回调可能更简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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