I've been trying to figure out how to solve this but was unsuccessful.
The problem here is after clicking the login button, it loads the Facebook Activity normally, and when it finishes, my activity receives the activity result and notifies the CallbackManager (all as described in the docs).
Unfortunately nothing happens from this point, no method from the registered FacebookCallback is executed, and not even a line is logged to inform of an error.
Here are the involved files:
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);
}
...
}
And activity_login.xml includes the button like this
<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 the Facebook Activity and APP ID in my android manifest 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" />
As well as the android app key in the facebook application.
Hope figures out a solution for this, thank you very much.
Ok I see now. This is probably wrong
callbackManager.onActivityResult(resultCode, resultCode, data);
See resultCode
is entered twice. What you want to do is:
callbackManager.onActivityResult(requestCode, resultCode, data);
Try adding this in your manifest.xml between application
<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" /><activity
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.