更新时间:2023-09-10 20:02:40
我们可以使用 GoogleSignInApi.silentSignIn()
方法,以检查登录凭据是否有效。
它返回一个 OptionalPendingResult
对象,该对象用于检查凭据是否有效。如果凭据有效,则 OptionalPendingResult
的 isDone()
方法将返回true。
然后,可以使用get方法立即获得结果(如果可用)。
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文档中的 OptionalPendingResult
:
https://developers.google.com/android/reference/com/google/android/gms/common/api/OptionalPendingResult
Android Documentation for OptionalPendingResult
:
https://developers.google.com/android/reference/com/google/android/gms/common/api/OptionalPendingResult
GoogleSignInApi
:
https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInApi
这是用于检查凭据是否有效的代码。
Here's the code for checking if the credentials are valid or not.
OptionalPendingResult<GoogleSignInResult> 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);
}