我在Android应用中使用以下代码段来要求用户登录Facebook
public class FacebookLoginActivity extends AppCompatActivity {
private CallbackManager callbackManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(this.getApplicationContext());
initCallback();
LoginManager.getInstance().logInWithReadPermissions(this, FacebookUtils.requiredPermissions);
}
private void initCallback() {
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken.setCurrentAccessToken(loginResult.getAccessToken());
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException exception) {
}
}
);
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
但是,回调中定义的方法永远不会被调用。有人可以帮帮我吗?