I am writing an app which requires user login.
I would like to implement it by Google+ and have followed the following articles to set-up my login activity Log
The silentSignIn method of GoogleSignInApi can be used to check the validity of cached credential of the user.
We can use GoogleSignInApi.silentSignIn() method to check if the login credential is valid or not.
It returns an OptionalPendingResult object which is used to check whether the credential is valid or not. If the credential is valid OptionalPendingResult's isDone() method will return true.
The get method can then be used to obtain the result immediately (If it is available).
Android Documentation for GoogleSignInApi:
https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInApi
Android Documentation for OptionalPendingResult:
https://developers.google.com/android/reference/com/google/android/gms/common/api/OptionalPendingResult
Here's the code for checking if the credentials are valid or not.
OptionalPendingResult opr = Auth.GoogleSignInApi.silentSignIn(google_api_client);
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);
}
Note - The method requires a GoogleApiClient object so please make sure that the googleapiclient object is connected before validation.