Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Plus sign in 'Choose an Account' dialog appears twice

I'm implementing Google+ sign in via the developer documentation. My onConnectionFailed methods is being called after I choose an account to sign in with the error RESOLUTION_REQUIRED (error code 6). This launches another 'Choose an Account' dialog which then works (takes me to permissions) if I select the same account. I'm not sure why it prompts another dialog. I start with resolveSignInError Any insight?

Also, selecting an account from 'Choose an account' shows permissions, if I hit cancel at that point and select another account from the dial, it shows the wrong picture for the permissions or sometimes no picture at all. I've also gotten An internal error has occurred toast once.

@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();
        }
    }
}
like image 543
ono Avatar asked Oct 29 '14 21:10

ono


2 Answers

In "onActivityForResult", you should remove the first line "super.onActivityResult(requestCode, resultCode, data);"

Also, just to be sure, you create your GoogleApiClient in onCreate, connect it in onStart() and disconnect it in onStop()?

Do you call resolveSignInError() from anywhere else in your code?

like image 138
FreewheelNat Avatar answered Nov 17 '22 23:11

FreewheelNat


The following code is working fine for me, Please update yours with it and check.

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();
            }
        }
    }
like image 1
MKJParekh Avatar answered Nov 17 '22 22:11

MKJParekh