首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检查用户是否已经使用Auth.GoogleSignInApi登录?

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

Stack Overflow用户
提问于 2016-02-04 08:10:10
回答 2查看 3.7K关注 0票数 7

我发现,为了在用户中签名,我必须使用以下代码:

代码语言:javascript
复制
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);

发出信号

代码语言:javascript
复制
new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    disconnect();
                }
            });

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

显然,在应用程序的设置(共享首选项)中保存“登录”是可能的,但是使用google的方法在哪里呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-02-04 10:19:47

这里我找到了解决方案:

代码语言:javascript
复制
  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);
                }
            });
        }
票数 10
EN

Stack Overflow用户

发布于 2018-01-05 05:35:54

在这里,我找到了这个问题的简单解决方案

代码语言:javascript
复制
GoogleSignInAccount lastSignedInAccount= GoogleSignIn.getLastSignedInAccount(context);
if(lastSignedInAccount==null){
// user has already logged in, you can check user's email, name etc from lastSignedInAccount
String email = lastSignedInAccount.getEmail();
}else{
// user is not logged in with any account
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35195673

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档