Android Facebook登录未显示登录成功对话框

时间:2015-04-20 02:10:12

标签: android facebook-android-sdk

我想在我的Android应用中实现分享帖功能 为此,我需要首先检查用户是否已登录,然后显示用户登录对话框。

成功登录后,我将显示“分享”对话框 当我单击登录按钮时,它会自动登录并且不会显示“登录”对话框。

我做错了什么?

FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_details);

LoginButton loginButton = (LoginButton) findViewById(R.id.fb_login_button);
// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
    @Override
    public void onSuccess(LoginResult loginResult) {
        Toast.makeText(getApplicationContext(),"in LoginResult on success", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onCancel() {
        Toast.makeText(getApplicationContext(),"in LoginResult on cancel", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onError(FacebookException exception) {
        Toast.makeText(getApplicationContext(),"in LoginResult on error", Toast.LENGTH_LONG).show();
    }
});

2 个答案:

答案 0 :(得分:0)

您应该拦截onActivityResult中的登录回调。

答案 1 :(得分:0)

就像上面提到的@inmyth一样,您需要通过CallbackManager将登录结果(失败,成功或取消)转发回onActivityResult(),如下所示:

/*Then in onActivityResult() forward the login results to the callbackManager created in onCreate():
   Every activity and fragment that you integrate with the FacebookSDK Login or
   Share should forward onActivityResult to the callbackManager.*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}

完成此操作后,您现在可以在onSuccess() onCancel()onFail()

中执行所需的代码