2014-10-29 19 views
7

Geliştirici dokümanları aracılığıyla Google+ oturum açıyorum. RESOLUTION_REQUIRED (Hata kodu 6) hatasıyla oturum açmak için bir hesap seçtikten sonra onConnectionFailed yöntemlerimi çağırıyor. Bu, aynı hesabı seçersem daha sonra çalışacak başka bir "Hesap Seç" iletişim kutusunu başlatır (izinlerimi alır). Neden başka bir diyalog sorduğundan emin değilim. resolveSignInError ile başlıyorum Herhangi bir anlayış?Google Plus 'Bir Hesap Seç' iletişim kutusu iki kez görüntüleniyor

Ayrıca, 'Bir hesap seç' seçeneğinden bir hesap seçmek izinleri gösterir, eğer o noktada iptal edersem ve kadrandan başka bir hesap seçerse, izinler için yanlış görüntüyü veya bazen hiç resim olmadığını gösterir. Ayrıca bir kez An internal error has occurred tost aldım.

@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(); 
     } 
    } 
} 

cevap

1

Aşağıdaki kod benim için iyi çalışıyor, Lütfen onunla güncelleyin ve kontrol edin. "Super.onActivityResult (requestCode, ResultCode, veri);"

"onActivityForResult" olarak
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

, ilk satırını kaldırmak gerekir

Ayrıca, emin olmak için, onCreate uygulamasında GoogleApiClient'inizi yaratın, onStart() 'a bağlayın ve onStop() ile bağlantısını kesin.

Kodunuzdaki başka bir yerden resolveSignInError() yöntemini çağırıyor musunuz?

+0

Teşekkürler. Ben bir super.onActivityForResult() vardı ve onu kaldırarak (sadece ben sonuçta kendimi işlemediğinde arama) sorunu çözdü. – Ridcully

0

getprofileinformation() işlevinde signout'u girin. Bunun gibi, bu kod size yardımcı olabilir

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(); 
     } 
    }