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

我想要为了登录用户我必须使用这段代码
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轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...