gpt4 book ai didi

android - 检查用户是否已经使用 Auth.GoogleSignInApi 登录?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:21:09 25 4
gpt4 key购买 nike

我发现为了让用户登录,我必须使用以下代码:

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

退出

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

但是当用户重新启动应用程序并且他已经登录(之前没有注销)时,是否有可能检测到这种“当前登录”状态?

显然,可以在应用程序的设置(共享首选项)中保存“已登录”,但是有什么方法可以使用 google api 进行检测?

最佳答案

Here我找到了解决方案:

  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);
}
});
}

关于android - 检查用户是否已经使用 Auth.GoogleSignInApi 登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35195673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com