2016-12-17 121 views
0

當我點擊第一次在谷歌登錄時,問我哪一個\ c將被選中,當多於1 a] c禮物。但第二次它沒有問,它的原子登錄與先前選定的\ c。谷歌登錄總是詢問要選擇哪個帳戶

如何可以總是顯示\ c中選擇

mGoogleApiClient = new GoogleApiClient.Builder(context) 
      .enableAutoManage((FragmentActivity) context, new GoogleApiClient.OnConnectionFailedListener() { 
       @Override 
       public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { 

       } 
      }) 
      .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 
      .build(); 

我累mGoogleApiClient.clearDefaultAccountAndReconnect(); 但它給了我崩潰的客戶端沒有連接

回答

1
You will have to use the revoke access callback. 

googleApiClient = new GoogleApiClient.Builder(this) 
        .enableAutoManage(LoginActivity.this , this) 
        .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 
        .addApi(AppIndex.API).build(); 

在登入]按鈕點擊

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient); 
        startActivityForResult(signInIntent, 100); 

在OnActivityResult

GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
      handleSignInResult(result); 

現在你犯了一個功能handleSignInResult(result),並使用所提供的信息由於在回調中訪問將被撤銷。 所以你在這裏獲得信息並做你想做的事情。

此回調添加到您的googleApiCLient

googleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { 
      @Override 
      public void onConnected(@Nullable Bundle bundle) { 
       if (googleApiClient.isConnected()) { 
        Auth.GoogleSignInApi.revokeAccess(googleApiClient).setResultCallback(
          new ResultCallback<Status>() { 
           @Override 
           public void onResult(@NonNull Status status) { 
            Log.e("getOut",status.toString()); 
           } 
          }); 
       } 
      } 
      @Override 
      public void onConnectionSuspended(int i) { 

      } 
     }); 

這個回調將撤消所有帳戶的訪問,並且將顯示對話框,選擇Gmail帳戶每次。

希望這有助於你。

+1

onConnected不會被調用 – andro

+1

signOut應該足夠用於本地設備,撤銷會導致這種情況發生在不同設備上...... https://developers.google.com/identity/sign-in/android/disconnect –