我有一项活动(登录)和一类(FacebookLogin)。
public void loginWithFacebook(boolean fetchUserInfo) {
Log.d(TAG, "Logging into Facebook.");
String applicationId = Utility.getMetadataApplicationId(activity
.getBaseContext());
mCurrentSession = Session.getActiveSession();
if (mCurrentSession == null || mCurrentSession.getState().isClosed()) {
Session session = new Session.Builder(activity.getBaseContext())
.setApplicationId(applicationId).build();
Session.setActiveSession(session);
} else {
Log.d(TAG, "SESSION open");
}
mCurrentSession = Session.getActiveSession();
if (!mCurrentSession.isOpened()) {
Session.OpenRequest openRequest = null;
openRequest = new Session.OpenRequest(activity);
if (openRequest != null) {
openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
openRequest.setPermissions(Arrays.asList("user_birthday",
"email", "user_hometown"));
openRequest
.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
mCurrentSession.openForRead(openRequest);
}
}
}
这是 Facebook 类的方法。在登录活动中指定 onActivityResult 方法。这很好用,除非用户在 Facebook 登录页面加载时点击任何地方。如果用户单击它调用 onActivityResult 类的任何位置。为什么会这样?