Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onConnectionFailed giving SIGN_IN_REQUIRED(4)

I am developing an Android application where I want to use the Google API. For that I have imported the google-play-service-lib project.

I am following this link to initialize GoogleApiClient object.

My code:

1) In the onCreate() method I am building the GoogleApiClient object:

mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .addApi(Plus.API, null)
    .addScope(Plus.SCOPE_PLUS_LOGIN)
    .build();

2) In onStart(), I call mGoogleApiClient.connect().

3) My activity implements ConnectionCallbacks and OnConnectionFailedListener.

4) My onConnectionFailed() method looks like:

public void onConnectionFailed(ConnectionResult result) {
    //in dubug result looks like : ConnectionResult{
    //statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent
                    // {41f8ca70: android.os.BinderProxy@41f8ca10}}
     try {
     if(!mIntentInProgress && result.hasResolution())
     {
         mIntentInProgress=true;
        result.startResolutionForResult(mActivity, RC_SIGN_IN);
          }

    } catch (SendIntentException e) {
        e.printStackTrace();
    }
}

5) My onActivityResult() method contains:

if (requestCode == RC_SIGN_IN) {
   if (!mGoogleApiClient.isConnecting()) {
      mGoogleApiClient.connect();
   }
}

When I run my app I get a Toast that says that an internal error popped up. I did create the project in the Google console.

like image 530
DCoder Avatar asked May 19 '14 11:05

DCoder


2 Answers

I had the same problem.

From documentation: The client may choose to continue without using the API or it may call startResolutionForResult(Activity, int) to prompt the user to sign in.

So you should try to sign in by using startResolutionForResult() function

@Override
public void onConnectionFailed(ConnectionResult result) {
   if (result.hasResolution()) {
       try {
           // !!!
           result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
       } catch (SendIntentException e) {
           mPlusClient.connect();
       }
   }

   mConnectionResult = result;
}
like image 192
user2642219 Avatar answered Oct 25 '22 21:10

user2642219


Just follow google's instructionss

AND CAUTION

Since you are still in development mode, check if you have added your testing email address in the GAME DETAILS center before publishing the game.

like image 41
Naskov Avatar answered Oct 25 '22 22:10

Naskov