6

Ho fonte che per accedere l'utente devo usare questo codice:Verifica se l'utente ha già effettuato l'accesso utilizzando Auth.GoogleSignInApi?

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 
startActivityForResult(signInIntent, RC_SIGN_IN); 

a SignOut

new ResultCallback<Status>() { 
       @Override 
       public void onResult(Status status) { 
        disconnect(); 
       } 
      }); 

Ma quando l'utente rilanciare l'applicazione e si è già connesso (e nessuna disconnessione prima) è possibile rilevare questo stato "attualmente connesso"?

Ovviamente, è possibile salvare "loggato" nelle impostazioni (preferenze condivise) dell'app ma è possibile trovare un modo per utilizzare google api?

risposta

10

Here ho trovato la soluzione:

OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient); 
     if (opr.isDone()) { 
      // If the user's cached credentials are valid, the OptionalPendingResult will be "done" 
      // and the GoogleSignInResult will be available instantly. 
      Log.d(TAG, "Got cached sign-in"); 
      GoogleSignInResult result = opr.get(); 
      handleSignInResult(result); 
     } else { 
      // If the user has not previously signed in on this device or the sign-in has expired, 
      // this asynchronous branch will attempt to sign in the user silently. Cross-device 
      // single sign-on will occur in this branch. 
      showProgressDialog(); 
      opr.setResultCallback(new ResultCallback<GoogleSignInResult>() { 
       @Override 
       public void onResult(GoogleSignInResult googleSignInResult) { 
        hideProgressDialog(); 
        handleSignInResult(googleSignInResult); 
       } 
      }); 
     } 
0

qui ho trovato le soluzioni semplici per questo

GoogleSignInAccount lastSignedInAccount= GoogleSignIn.getLastSignedInAccount(context); 
if(lastSignedInAccount==null){ 
// user has already logged in, you can check user's email, name etc from lastSignedInAccount 
String email = lastSignedInAccount.getEmail(); 
}else{ 
// user is not logged in with any account 
} 
+0

Questo è in realtà una versione più recente. La versione di SDK dei servizi di riproduzione deve essere 11.6+. – Jenix