nileshbirhade
nileshbirhade

Reputation: 837

Strange error while integrating Google plus

I am integrating google plus in my application from this URL https://developers.google.com/+/mobile/android/sign-in but i am not able to get chooser of google plus account to login and in ConnectionResult i always get ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{4223c668: android.os.BinderProxy@4224b9c0}}... I tried lots of links and created and deleted client id its not working for me Here is my Code

@Override
protected void onCreate(Bundle savedInstanceState) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
                    .addApi(Plus.API)
        .addScope(Plus.SCOPE_PLUS_LOGIN).build();

    btnGooglePlus = (SignInButton) findViewById(R.id.sign_in_button);
    btnGooglePlus.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (v.getId() == R.id.sign_in_button
                    && !mGoogleApiClient.isConnecting()) {
                mSignInClicked = true;
            }
        }
    });


}

@Override
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
}

@Override
protected void onStop() {
    super.onStop();
    if (mGoogleApiClient.isConnected()) {
        mGoogleApiClient.disconnect();
    }
}

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

@Override
public void onConnectionFailed(ConnectionResult result) {

    if (!mIntentInProgress) {
        // Store the ConnectionResult so that we can use it later when the
        // user clicks
        // 'sign-in'.
        mConnectionResult = result;

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

@Override
public void onConnected(Bundle arg0) {
    Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();
}

@Override
public void onConnectionSuspended(int cause) {
    mGoogleApiClient.connect();
}

/* A helper method to resolve the current ConnectionResult error. */
private void resolveSignInError() {
    if (mConnectionResult.hasResolution()) {
        try {


    mIntentInProgress = true;
            mConnectionResult.startResolutionForResult(this,       RC_SIGN_IN);

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

Upvotes: 0

Views: 199

Answers (1)

Scarygami
Scarygami

Reputation: 15569

You don't do anything in your OnClickListener.

You need to call resolveSignInError() from onClick, which will recognize the SIGN_IN_REQUIRED and start the login flow accordingly.

Upvotes: 1

Related Questions