Make sure the user is already registered using Auth.GoogleSignInApi?

I want to use this code to enter my account:

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

for conclusion

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

But when the user restarts the application, and he has already logged in (and will not log out before), is it possible to detect this state "currently logged in"?

Obviously, in the settings (general settings) of the application, you can save "logged in", but is there a way to detect using google api?

+6
source share
2 answers

Here I found a solution:

  OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient); if (opr.isDone()) { // If the user 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); } }); } 
+10
source

Here I found simple solutions for this.

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

All Articles