Google Plus登录“选择帐户”对话框会出现两次

我正在通过开发者文档实施Google+登录。 在我选择要使用RESOLUTION_REQUIRED (错误代码6)错误登录的帐户后,我的onConnectionFailed方法才会被调用。 这将启动另一个“选择一个帐户”对话框,然后运行(带我去权限),如果我选择相同的帐户。 我不确定为什么会提示另一个对话框。 我从resolveSignInError开始任何见解?

另外,从“选择一个帐户”中选择一个帐户会显示权限,如果我在该时间点取消取消,并从拨号中选择另一个帐户,则会显示权限错误的图片或根本没有图片。 我也得到了An internal error has occurred

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

以下代码对我来说工作正常,请更新您的密码并进行检查。

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

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

另外,可以肯定的是,您在onCreate中创建您的GoogleApiClient,将其连接到onStart()并在onStop()中断开连接?

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


在getprofileinformation()中输入signout函数。 喜欢这个。希望,这段代码可以帮助你

 private void getProfileInformation() {
        try {
            if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
                Person currentPerson = Plus.PeopleApi
                        .getCurrentPerson(mGoogleApiClient);
                String personName = currentPerson.getDisplayName();
                String personPhotoUrl = currentPerson.getImage().getUrl();
                String personGooglePlusProfile = currentPerson.getUrl();
                String email = Plus.AccountApi.getAccountName(mGoogleApiClient);

                forget_login_txt.setText(personName+"   "+email);
                Log.e(TAG, "Name: " + personName + ", plusProfile: "
                        + personGooglePlusProfile + ", email: " + email
                        + ", Image: " + personPhotoUrl);


                personPhotoUrl = personPhotoUrl.substring(0,
                        personPhotoUrl.length() - 2)
                        + PROFILE_PIC_SIZE;


                signOutFromGplus();



            } else {
                Toast.makeText(getApplicationContext(),
                        "Person information is null", Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
链接地址: http://www.djcxy.com/p/23297.html

上一篇: Google Plus sign in 'Choose an Account' dialog appears twice

下一篇: CoAP and DTLS integration