我最近升級了我的代碼以使用FB android SDK 3.0。我的應用程序有四個活動,不使用片段。奇怪的是我的代碼在android 2.3.4上沒有任何問題。但在Android 4.0.4中,會話狀態始終爲「開放」。我使用UiLifeCycleHelper,下面是啓動器活動中的代碼。Facebook android sdk 3.0登錄問題
SharedPreferences mPrefs;
String access_token = mPrefs.getString("access_token", null);
Session currentSession = Session.getActiveSession();
if(currentSession == null || currentSession.getState().isClosed())
{
if(access_token!=null)
{
SharedPreferences.Editor editor = mPrefs.edit();
//One time upgrade from FB SDK 2.0 to 3.0
editor.putString("access_token", null);
editor.commit();
AccessToken new_access_token = AccessToken.createFromExistingAccessToken(access_token, null, null, null, null);
currentSession.open(new_access_token, myCallback);
Session.setActiveSession(currentSession);
}
else
{
Session.openActiveSession(this, true, myCallback);
}
}
else if (!currentSession.isOpened())
{
OpenRequest openRequest = new OpenRequest(this).setCallback(myCallback);
openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
openRequest.setPermissions(Arrays.asList(permissions));
openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
currentSession.openForRead(openRequest);
}
else if(currentSession.isOpened())
{
handleRequest(currentSession);
}
StatusCallback myCallback = new StatusCallback()
{
@Override
public void call(Session session, SessionState state, Exception exception)
{
handleRequest(session);
}
};
public void handleRequest(Session activeSession)
{
Request new_request = new Request(activeSession, "/me/friends", null, null, new Callback()
{
@Override
public void onCompleted(Response response)
{
//Process the response and make UI changes.
}
});
}
首先,我懷疑問題是由於舊版本的Facebook應用程序(1.9)造成的。所以我升級到最新版本(3.2)。仍然問題仍然存在於Android 4.0.4上。
這是我在onActivityResult回調
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
uihelper.onActivityResult(requestCode, resultCode, data);
}
代碼有什麼錯?
請參閱我的編輯。我經歷了你提到的問題。我使用ListActivity而不是Activity。那是問題嗎? – 2013-05-13 06:01:58