android - Google Plus 登录 'Choose an Account' 对话框出现两次

标签 android google-plus

我正在通过开发者文档实现 Google+ 登录。在我选择要登录的帐户时出现错误 RESOLUTION_REQUIRED(错误代码 6)后,将调用我的 onConnectionFailed 方法。这将启动另一个“选择帐户”对话框,如果我选择相同的帐户,该对话框将起作用(带我进入权限)。我不确定为什么它会提示另一个对话框。我从 resolveSignInError 开始,有什么见解吗?

此外,从“选择一个帐户”中选择一个帐户会显示权限,如果我此时点击取消并从拨号盘中选择另一个帐户,它会显示错误的权限图片,有时甚至根本没有图片。我还收到了一次 An internal error has occurred toast。

@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, 0, 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();
        }
    }
}

最佳答案

在“onActivityForResult”中,你应该删除第一行“super.onActivityResult(requestCode, resultCode, data);”

另外,为了确定,您在 onCreate 中创建 GoogleApiClient,在 onStart() 中连接它并在 onStop() 中断开连接?

您是否从代码中的其他任何地方调用 resolveSignInError()?

关于android - Google Plus 登录 'Choose an Account' 对话框出现两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26640735/

相关文章:

android - 找不到adb请设置ANDROID_HOME环境变量为Android SDK根目录路径

android - java.lang.NullPointerException 与 Google +1 按钮集成

ios - Google+ 登录崩溃

android - 适用于平板电脑的 Google+ Android 网格小部件教程

android - 同时制作 fragment 过渡动画 View

java - 通过 JNI 将 C++ 字符串发送到 Java

java - 组织.gradle.process.internal.ExecException : Process 'command finished with non-zero exit value 1

java - 在 Android 应用程序中将评论文本包装在用户名下方

audio - 使用 ffmpeg 编码声音以在 Google Hangouts 应用程序中播放

android - 没有帐户选择对话框的 Google Plus GoogleApiClient connect()