title: <Your App> is having trouble with Google Play services - When using GoogleApiClient, it always trigger onConnectionFailed
body: <p>Currently, my app is using</p>
  
  <ul>
  <li>minSdkVersion 14</li>
  <li>targetSdkVersion 23</li>
  <li>compile 'com.google.android.gms:play-services-gcm:8.4.0'</li>
  <li>compile 'com.google.android.gms:play-services-base:8.4.0'</li>
  <li>compile 'com.google.android.gms:play-services-analytics:8.4.0'</li>
  <li>compile 'com.google.android.gms:play-services-ads:8.4.0'</li>
  <li>compile 'com.google.android.gms:play-services-drive:8.4.0'</li>
  </ul>
  
  <p>I am using the following code to perform <code>GoogleApiClient</code> connection.</p>
  
  <pre><code>public class GoogleApiClientFragment extends Fragment implements
          GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
  
      public interface ConnectionCallbacks {
          void onConnected(GoogleApiClient googleApiClient, int action);
          void onCancel(int action);
      }
  
      public static GoogleApiClientFragment newInstance(String accountName, int action) {
          GoogleApiClientFragment googleApiClientFragment = new GoogleApiClientFragment();
          Bundle bundle = new Bundle();
          bundle.putString(INTENT_EXTRA_ACCOUNT_NAME, accountName);
          bundle.putInt(INTENT_EXTRA_ACTION, action);
          googleApiClientFragment.setArguments(bundle);
          return googleApiClientFragment;
      }
  
      /**
       * Handles resolution callbacks.
       */
      @Override
      public void onActivityResult(int requestCode, int resultCode,
                                      Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
  
          if (requestCode == RequestCode.REQUEST_GOOGLE_API_CLIENT_CONNECT) {
              if (resultCode == Activity.RESULT_OK) {
                  mGoogleApiClient.connect();
              } else {
                  Activity activity = this.getActivity();
                  if (activity instanceof ConnectionCallbacks) {
                      ConnectionCallbacks connectionCallbacks = (ConnectionCallbacks)activity;
                      connectionCallbacks.onCancel(action);
                  }
              }
          }
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setRetainInstance(true);
  
          Bundle bundle = this.getArguments();
          this.accountName = bundle.getString(INTENT_EXTRA_ACCOUNT_NAME);
          this.action = bundle.getInt(INTENT_EXTRA_ACTION);
      }
  
      @Override
      public void onResume() {
          super.onResume();
          if (mGoogleApiClient == null) {
              mGoogleApiClient = new GoogleApiClient.Builder(this.getContext())
                      .setAccountName(accountName)
                      .addApi(Drive.API)
                      .addScope(Drive.SCOPE_FILE)
                      .addScope(Drive.SCOPE_APPFOLDER)
                      .addConnectionCallbacks(this)
                      .addOnConnectionFailedListener(this)
                      .build();
  
              mGoogleApiClient.connect();
          }
      }
  
      @Override
      public void onConnected(Bundle bundle) {
          Log.i(TAG, "GoogleApiClient connected");
  
          Activity activity = this.getActivity();
          if (activity instanceof ConnectionCallbacks) {
              ConnectionCallbacks connectionCallbacks = (ConnectionCallbacks)activity;
              connectionCallbacks.onConnected(mGoogleApiClient, action);
          }
      }
  
      @Override
      public void onConnectionSuspended(int i) {
          Log.i(TAG, "GoogleApiClient connection suspended");
      }
  
      @Override
      public void onConnectionFailed(ConnectionResult connectionResult) {
          Log.i(TAG, "GoogleApiClient connection failed: " + connectionResult.toString());
  
          if (!connectionResult.hasResolution()) {
              Utils.showLongToast("debug two " + connectionResult.toString());
  
              // show the localized error dialog.
              GoogleApiAvailability.getInstance().getErrorDialog(this.getActivity(), connectionResult.getErrorCode(), 0).show();
              return;
          }
          try {
              connectionResult.startResolutionForResult(this.getActivity(), RequestCode.REQUEST_GOOGLE_API_CLIENT_CONNECT);
          } catch (IntentSender.SendIntentException e) {
              Log.e(TAG, "Exception while starting resolution activity", e);
          }
      }
  
      private String accountName = null;
      private int action = -1;
      private GoogleApiClient mGoogleApiClient;
  
      public static final int ACTION_LOAD_FROM_CLOUD = 0;
      public static final int ACTION_SAVE_TO_CLOUD = 1;
      private static final String INTENT_EXTRA_ACCOUNT_NAME = "INTENT_EXTRA_ACCOUNT_NAME";
      private static final String INTENT_EXTRA_ACTION = "INTENT_EXTRA_ACTION";
  
      private static final String TAG = "GoogleApiClientFragment";
  }
  </code></pre>
  
  <p>Certain users (Not all users) are hit with the following problem.</p>
  
  <blockquote>
    <p> is having trouble with Google Play services. If the problem
    persists, please contact the developer for assistance.</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/X7JID.png" rel="noreferrer"><img src="https://i.stack.imgur.com/X7JID.png" alt="enter image description here"></a></p>
  
  <p>The error dialog box is due to the <code>GoogleApiAvailability.getInstance().getErrorDialog</code> code in <code>onConnectionFailed</code>.</p>
  
  <p>Whenever</p>
  
  <pre><code>        mGoogleApiClient = new GoogleApiClient.Builder(this.getContext())
                  .setAccountName(accountName)
                  .addApi(Drive.API)
                  .addScope(Drive.SCOPE_FILE)
                  .addScope(Drive.SCOPE_APPFOLDER)
                  .addConnectionCallbacks(this)
                  .addOnConnectionFailedListener(this)
                  .build();
  </code></pre>
  
  <p>is executed, it always hit</p>
  
  <pre><code>@Override
  public void onConnectionFailed(ConnectionResult connectionResult) {
  </code></pre>
  
  <p>When I print out connectionResult using <code>toString</code>, it gives</p>
  
  <pre><code>ConnectionResult{statusCode=INTERNAL_ERROR, resolution=null, message=null}
  </code></pre>
  
  <p>One of my users is having the following spec.</p>
  
  <ul>
  <li>Sony Xperia z5</li>
  <li>Android 6</li>
  <li>Google Play Services 9.0.83</li>
  <li>Only 1 Google account in his device</li>
  </ul>
  
  <p>I even try to re-compile the APK with Google Play Services 9.0.1. But, the same problem still occur.</p>
  
  <p>Any idea, on how I can resolve the problem?</p>