我正在通过开发人员文档实施Google登录.在我选择要使用错误RESOLUTION_required(错误代码6)登录的帐户后,我的onConnectionFailed方法被调用.这将启动另一个“选择一个帐户”对话框,如果我选择相同的帐户,该对话框将起作用(转到我的权限).我不确定为什么它会提示另一个对话框.我从resolveSignInError开始有任何见解?
此外,从“选择一个帐户”中选择一个帐户会显示权限,如果我在此时点击取消并从拨号盘中选择另一个帐户,则会显示错误的权限图片或有时根本没有图片.我也得到了一次内部错误.
@Override public void onConnectionFailed(ConnectionResult connectionResult) { if (!mIntentInProgress) { // Store the ConnectionResult so that we can use it later when the user clicks // 'sign-in'. mConnectionResult = connectionResult; if (mSignInClicked) { // The user has already clicked 'sign-in' so we attempt to resolve all // errors until the user is signed in,or they cancel. resolveSignInError(); } } } private void resolveSignInError() { if (mConnectionResult != null && mConnectionResult.hasResolution()) { try { mIntentInProgress = true; startIntentSenderForResult(mConnectionResult.getResolution().getIntentSender(),RC_SIGN_IN,null,0); } catch (IntentSender.SendIntentException e) { // The intent was canceled before it was sent. Return to the default // state and attempt to connect to get an updated ConnectionResult. mIntentInProgress = false; mGoogleApiClient.connect(); } } } @Override public void onActivityResult(int requestCode,int resultCode,Intent data) { super.onActivityResult(requestCode,resultCode,data); if (requestCode == RC_SIGN_IN) { if (resultCode != RESULT_OK) { mSignInClicked = false; } mIntentInProgress = false; if (!mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } } }
解决方法
以下代码对我来说工作正常,请用它更新你的并检查.
private void resolveSignInError() { if (mConnectionResult.hasResolution()) { try { mIntentInProgress = true; mConnectionResult.startResolutionForResult(this,RC_SIGN_IN); } catch (SendIntentException e) { mIntentInProgress = false; mGoogleApiClient.connect(); } } } @Override public void onConnectionFailed(ConnectionResult result) { if (!result.hasResolution()) { GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(),this,0).show(); return; } if (!mIntentInProgress) { mConnectionResult = result; if (mSignInClicked) { resolveSignInError(); } } } @Override protected void onActivityResult(int requestCode,int responseCode,Intent intent) { if (requestCode == RC_SIGN_IN) { if (responseCode != RESULT_OK) { mSignInClicked = false; } mIntentInProgress = false; if (!mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } } }