1

我想使用Facebook登錄按鈕,但unflexalately它自動登錄,我想讓它自動登出和用戶按它然後登錄過程開始,我知道它會自動登錄,因爲我我在我的android facebook應用程序中登錄。android facebook登錄按鈕自動登錄

碼/ H3>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <com.facebook.widget.LoginButton 
     android:id="@+id/authButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="30dp" 
     /> 

</LinearLayout> 

回答

0
In onCreate method. 


     Session activeSession = Session.getActiveSession(); 
     if (activeSession == null || activeSession.getState().isClosed()) { 
      activeSession = new Session.Builder(context).setApplicationId(context.getString(R.string.app_id)).build(); 
      activieSession = Session.setActiveSession(activeSession); 
     } 
     Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); 

     LoginButton login = (LoginButton)findViewById(R.id.login); 
     login.setReadPermissions(Arrays.asList("user_groups", "user_photos")); 


@Override 
public void onResume() { 
    super.onResume(); 
    // For scenarios where the main activity is launched and user 
    // session is not null, the session state change notification 
    // may not be triggered. Trigger it if it's open/closed. 
    Session session = Session.getActiveSession(); 
    if (session != null && (session.isOpened() || session.isClosed())) { 
     onSessionStateChange(session, session.getState(), null); 
    } 
    uiHelper.onResume(); 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    uiHelper.onActivityResult(requestCode, resultCode, data); 
    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); 
} 
2

其實,如果我理解正確的問題,你想要什麼MuhammadAamirALi貼相反。什麼應該是這樣的:在OnCreate方法

Session activeSession = Session.getActiveSession(); 
    //Checks for an open session 
    if (!(activeSession == null || activeSession.getState().isClosed())) { 
     //if found one, kill it. 
     activeSession.closeAndClearTokenInformation(); 
    } 
    LoginButton authButton = (LoginButton) layout.findViewById(R.id.authButton); 
    authButton.setReadPermissions(Arrays.asList("basic_info", "email")); 

如果有人的實現同樣的更好的辦法知道,我很想知道(因爲我面對這個問題馬上)。就像,如何防止Facebook在創建按鈕時檢查打開的會話。

+0

這仍然是最好的方式或是新發現的東西? – Lion789