2014-10-29 87 views
7

我正在通過開發者文檔實施Google+登錄。在我選擇要登錄的帳戶並使用錯誤RESOLUTION_REQUIRED(錯誤代碼6)之後,我的onConnectionFailed方法正在被調用。這將啓動另一個「選擇一個帳戶」對話框,然後運行(帶我去權限),如果我選擇相同的帳戶。我不確定爲什麼會提示另一個對話框。我從resolveSignInError開始任何見解?谷歌加登錄「選擇帳戶」對話框出現兩次

此外,從「選擇帳戶」中選擇一個帳戶將顯示權限,如果我在該點擊取消並從撥號中選擇另一個帳戶,則會顯示錯誤的權限圖像或根本沒有圖像。我也得到An internal error has occurred烤麪包一次。

@Override 
public void onConnectionFailed(ConnectionResult connectionResult) { 
    if (!mIntentInProgress) { 
     // Store the ConnectionResult so that we can use it later when the user clicks 
     // 'sign-in'. 
     mConnectionResult = connectionResult; 
     if (mSignInClicked) { 
      // The user has already clicked 'sign-in' so we attempt to resolve all 
      // errors until the user is signed in, or they cancel. 
      resolveSignInError(); 
     } 
    } 
} 

private void resolveSignInError() { 
    if (mConnectionResult != null && mConnectionResult.hasResolution()) { 
     try { 
      mIntentInProgress = true; 
      startIntentSenderForResult(mConnectionResult.getResolution().getIntentSender(), 
        RC_SIGN_IN, null, 0, 0, 0); 

     } catch (IntentSender.SendIntentException e) { 
      // The intent was canceled before it was sent. Return to the default 
      // state and attempt to connect to get an updated ConnectionResult. 
      mIntentInProgress = false; 
      mGoogleApiClient.connect(); 
     } 
    } 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == RC_SIGN_IN) { 
     if (resultCode != RESULT_OK) { 
      mSignInClicked = false; 
     } 
     mIntentInProgress = false; 
     if (!mGoogleApiClient.isConnecting()) { 
      mGoogleApiClient.connect(); 
     } 
    } 
} 

回答

1

下面的代碼對我來說工作正常,請更新你的它並檢查。

private void resolveSignInError() { 
     if (mConnectionResult.hasResolution()) { 
      try { 
       mIntentInProgress = true; 
       mConnectionResult.startResolutionForResult(this, RC_SIGN_IN); 
      } catch (SendIntentException e) { 
       mIntentInProgress = false; 
       mGoogleApiClient.connect(); 
      } 
     } 
    } 

    @Override 
    public void onConnectionFailed(ConnectionResult result) { 
     if (!result.hasResolution()) { 
      GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 0).show(); 
      return; 
     } 

     if (!mIntentInProgress) { 

      mConnectionResult = result; 

      if (mSignInClicked) { 

       resolveSignInError(); 
      } 
     } 

    } 

    @Override 
    protected void onActivityResult(int requestCode, int responseCode, Intent intent) { 
     if (requestCode == RC_SIGN_IN) { 
      if (responseCode != RESULT_OK) { 
       mSignInClicked = false; 
      } 

      mIntentInProgress = false; 

      if (!mGoogleApiClient.isConnecting()) { 
       mGoogleApiClient.connect(); 
      } 
     } 
    } 
2

在 「onActivityForResult」,應刪除第一行的 「super.onActivityResult(requestCode,resultCode爲,數據);」

另外,可以肯定的是,您在onCreate中創建您的GoogleApiClient,將其連接到onStart()並在onStop()中斷開連接?

您是否在代碼中的任何其他位置調用resolveSignInError()?

+0

謝謝。我有一個super.onActivityForResult()並將其刪除(僅當我不處理結果時才調用它)解決了問題。 – Ridcully 2015-12-19 18:05:43

0

在getprofileinformation()中輸入signout函數。喜歡that.Hope,此代碼可以幫助您

private void getProfileInformation() { 
     try { 
      if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { 
       Person currentPerson = Plus.PeopleApi 
         .getCurrentPerson(mGoogleApiClient); 
       String personName = currentPerson.getDisplayName(); 
       String personPhotoUrl = currentPerson.getImage().getUrl(); 
       String personGooglePlusProfile = currentPerson.getUrl(); 
       String email = Plus.AccountApi.getAccountName(mGoogleApiClient); 

       forget_login_txt.setText(personName+" "+email); 
       Log.e(TAG, "Name: " + personName + ", plusProfile: " 
         + personGooglePlusProfile + ", email: " + email 
         + ", Image: " + personPhotoUrl); 


       personPhotoUrl = personPhotoUrl.substring(0, 
         personPhotoUrl.length() - 2) 
         + PROFILE_PIC_SIZE; 


       signOutFromGplus(); 



      } else { 
       Toast.makeText(getApplicationContext(), 
         "Person information is null", Toast.LENGTH_LONG).show(); 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
相關問題