Si estas usando el google Sign-in
El mismo SDK realiza el guardado de los datos, este es un ejemplo de una Activity
que implementa GoogleApiClient.OnConnectionFailedListener
, la variable result
que es un tipo GoogleSignInResult
contiene los datos de tu autenticación, si es que fue realizada con anterioridad:
@Override
public void onStart() {
super.onStart();
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);
}
});
}
}
a partir de GoogleSignInResult
podemos acceder a los datos, por ejemplo:
GoogleSignInAccount acct = result.getSignInAccount();
Log.i("Google Sign in","DisplayName(): " + acct.getDisplayName());
Log.i("Google Sign in","Email: " + acct.getEmail());
Log.i("Google Sign in","IdToken: " + acct.getIdToken());
En cuanto al comentario de @FrancoLondra, Acerca de Firebase, la implementación es muy sencilla y una de las ventajas es que puedes autenticar con diversas comunidades.
