Why is there no response at all after calling onActivityResult() on CallbackManager using the Facebook login button?
I’ve been trying to figure out how to fix this, but without success.
The problem here is that after clicking the login button, it loads the Facebook activity normally, and when it completes, my activity receives the activity result and notifies the CallbackManager (all as described in the documentation).
Unfortunately, nothing happened at this point, and none of the methods in the registered Facebook Callback were executed, not even a single line was logged to notify the error.
Here are the documents involved:
public class LoginActivity extends Activity
CallbackManager callbackManager;
LoginButton loginFacebook;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(this);
setContentView(R.layout.activity_login);
...
callbackManager = CallbackManager.Factory.create();
loginFacebook = (LoginButton) findViewById(R.id.login_button);
loginFacebook.setReadPermissions("public_profile","email");
loginFacebook.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
...
(This is never executed)
}
@Override
public void onCancel() {
...
(Not executed)
}
@Override
public void onError(FacebookException e) {
...
(Not executed either)
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(resultCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}
...
}
activity_login.xml contains such a button
<com.facebook.login.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"/>
I also added Facebook Activity and App ID to my android list file
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />
and Android App Key in the Facebook app.
Hope to fix this, thank you very much.
Solution
Okay, I understand now. This may be wrong
callbackManager.onActivityResult(resultCode, resultCode, data);
See that resultCode
is entered twice. What you want to do is:
callbackManager.onActivityResult(requestCode, resultCode, data);