Currently, my app is using
- minSdkVersion 14
- targetSdkVersion 23
- compile 'com.google.android.gms:play-services-gcm:8.4.0'
- compile 'com.google.android.gms:play-services-base:8.4.0'
- compile 'com.google.android.gms:play-services-analytics:8.4.0'
- compile 'com.google.android.gms:play-services-ads:8.4.0'
- compile 'com.google.android.gms:play-services-drive:8.4.0'
I am using the following code to perform GoogleApiClient
connection.
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";
}
Certain users (Not all users) are hit with the following problem.
is having trouble with Google Play services. If the problem persists, please contact the developer for assistance.
The error dialog box is due to the GoogleApiAvailability.getInstance().getErrorDialog
code in onConnectionFailed
.
Whenever
mGoogleApiClient = new GoogleApiClient.Builder(this.getContext())
.setAccountName(accountName)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
is executed, it always hit
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
When I print out connectionResult using toString
, it gives
ConnectionResult{statusCode=INTERNAL_ERROR, resolution=null, message=null}
One of my users is having the following spec.
- Sony Xperia z5
- Android 6
- Google Play Services 9.0.83
- Only 1 Google account in his device
I even try to re-compile the APK with Google Play Services 9.0.1. But, the same problem still occur.
Any idea, on how I can resolve the problem?