GoogleApiClient connection always fails the first time, but the second successful completion

I have google plus login configured for an application via GoogleApiClient .

Whenever the application is installed for the first time and tries to make a connection through GoogleApiClient , it never becomes successful and always ends with onConnectionFailed with the result containing:

 ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{4130e760: android.os.BinderProxy@4130e700 }} 

But when you re- onConnected system, his name becomes successful and onConnected hits. Why is it possible to make it successful on the first try?

Is there something wrong with my Builder options?

 public void connectGoogleApi() { mGoogleApiClient = new GoogleApiClient.Builder(mainAppContext).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN).build(); mGoogleApiClient.connect(); } public void onConnectionFailed(ConnectionResult result) { if (!result.hasResolution()) { GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 0).show(); return; } if (!mIntentInProgress) { // Store the ConnectionResult for later usage mConnectionResult = result; resolveSignInError(); } } 
+7
android google-api-client
source share
2 answers

As stated in the official docs here :

If you use GoogleApiClient to connect to APIs that require authentication, such as Google Drive or Google Play Games, there is a good chance that your first connection attempt will fail and your application will receive an onConnectionFailed () call with a SIGN_IN_REQUIRED error because the user account not specified.

+2
source share

I had the same problem, calling 'connect ()' again, this time inside the onConnected method fixed it. It’s strange.

 @Override public void onConnected(final Bundle arg0) { Logger.log("On connected"); DevicePreferences.getGoogleApiClient().connect(); } 
0
source share

All Articles