В настоящее время мое приложение использует
- 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'
Я использую следующий код для выполнения соединения GoogleApiClient
.
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";
}
Некоторые пользователи (не все пользователи) имеют следующую проблему.
возникает проблема с сервисами Google Play. Если проблема сохраняется, обратитесь за помощью к разработчику.
Диалоговое окно ошибки связано с кодом GoogleApiAvailability.getInstance().getErrorDialog
в onConnectionFailed
.
Если
mGoogleApiClient = new GoogleApiClient.Builder(this.getContext())
.setAccountName(accountName)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Выполняется он всегда попадает
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Когда я распечатываю connectionResult с помощью toString
, он дает
ConnectionResult{statusCode=INTERNAL_ERROR, resolution=null, message=null}
Один из моих пользователей имеет следующую спецификацию.
- Sony Xperia z5
- Android 6
- Службы Google Play 9.0.83
- Только 1 учетная запись Google на своем устройстве
Я даже пытаюсь перекомпилировать APK с помощью Google Play Services 9.0.1. Но та же проблема все еще возникает.
Любая идея, как я могу решить проблему?