Android Google登录api始终调用onResume()
今天,我正在尝试实现Google登录API: 和实现接口 MainActivity(AppCompativeActivity)上的GoogleAppClient.ConnectionCallbacks、GoogleAppClient.OnConnectionFailedListener。但是,第一次登录时一切正常。当我打开新活动并再次返回时,总是调用onConnected()。如何避免在MainActivity onResume时调用OnConnectiond()?您必须Android Google登录api始终调用onResume(),android,onresume,google-signin,Android,Onresume,Google Signin,今天,我正在尝试实现Google登录API: 和实现接口 MainActivity(AppCompativeActivity)上的GoogleAppClient.ConnectionCallbacks、GoogleAppClient.OnConnectionFailedListener。但是,第一次登录时一切正常。当我打开新活动并再次返回时,总是调用onConnected()。如何避免在MainActivity onResume时调用OnConnectiond()?您必须 google_api_
google_api_client.connect()
在onStart()方法中,它将一次又一次地连接它。您可以通过为SignInButton click创建一个标志,并在连接google_api_客户端之前在onStart()方法中检查标志来修复此问题
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken("server_client_id") //to require server return Id token
.requestServerAuthCode("server_client_id") //to require server return authCode
.build();
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
GoogleSignInAccount acct = result.getSignInAccount();
String personName = acct.getDisplayName();
String personEmail = acct.getEmail();
String personId = acct.getId();
Uri personPhoto = acct.getPhotoUrl();
String tokenKey = acct.getServerAuthCode(); //get authenticated code to save in client
加油 不,我没有将connect()放在onStart()中,我会在按下自定义按钮时调用它。您好@GiapLee,我正在尝试您的解决方案,但只有getIdToken()、getServerAuthCode()为空,因此,我无法保存到SharedReference。有什么帮助吗?有。您可以从服务器获取任何authen字符串以保存到客户端。Hi@GiapLee、getIdToken()和getServerAuthCode()为空,我使用的是MIUI操作系统,Google服务版本为8.7。在项目中使用谷歌服务认证:8.4.0。所有都是最新的应用程序。我更新了代码。你需要修改一些关于谷歌签名的东西