2014-10-29 3 views
7

개발자 문서를 통해 Google+ 로그인을 구현 중입니다. RESOLUTION_REQUIRED (오류 코드 6)으로 로그인하기 위해 계정을 선택하면 내 onConnectionFailed 메쏘드가 호출됩니다. 그러면 다른 계정 'Choose an Account'대화 상자가 열리고 동일한 계정을 선택하면 작동합니다 (권한으로 이동). 왜 다른 대화 상자를 불러올 지 모르겠습니다. 내가 처음으로 resolveSignInError 어떤 통찰력?Google Plus 로그인 '계정 선택'대화 상자가 두 번 나타납니다.

또한 '계정 선택'에서 계정을 선택하면 사용 권한이 표시됩니다. 그 시점에서 취소를 누르고 다이얼에서 다른 계정을 선택하면 사용 권한에 대해 잘못된 그림이 표시되거나 전혀 그림이 표시되지 않습니다. 나는 또한 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

다음 코드는 문제가 해결되지 않았으므로 여기를 클릭하여 업데이트하고 확인하십시오. "super.onActivityResult (requestCode가,의 resultCode, 데이터);"

"onActivityForResult"에서
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

, 당신은 첫 번째 줄을 제거해야합니다

확실한 것은 onCreate에서 GoogleApiClient를 만들고 onStart()에서 연결 한 다음 onStop()에서 연결을 끊으시겠습니까?

코드의 다른 곳에서 resolveSignInError()를 호출합니까?

+0

감사합니다. 나는 super.onActivityForResult()를 가지고 그것을 제거했다. (내가 직접 결과를 처리하지 않을 때에 만 그것을 호출한다.) 문제가 해결되었다. – Ridcully

0

getprofileinformation()에 signout 함수를 입력하십시오. 좋아요,이 코드는 당신을 도울 수 있습니다

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(); 
     } 
    } 
관련 문제