@Override public String toString() { return "SignInFailureReason(serviceErrorCode:" + GameHelperUtils.errorCodeToString(mServiceErrorCode) + ((mActivityResultCode == NO_ACTIVITY_RESULT_CODE) ? ")" : (",activityResultCode:" + GameHelperUtils.activityResponseCodeToString(mActivityResultCode) + ")")); }
/** Handles a connection failure. */ @Override public void onConnectionFailed(ConnectionResult result) { // save connection result for later reference debugLog("onConnectionFailed"); mConnectionResult = result; debugLog("Connection failure:"); debugLog(" - code: " + GameHelperUtils.errorCodeToString(mConnectionResult.getErrorCode())); debugLog(" - resolvable: " + mConnectionResult.hasResolution()); debugLog(" - details: " + mConnectionResult.toString()); int cancellations = getSignInCancellations(); boolean shouldResolve = false; if (mUserInitiatedSignIn) { debugLog("onConnectionFailed: WILL resolve because user initiated sign-in."); shouldResolve = true; } else if (mSignInCancelled) { debugLog("onConnectionFailed WILL NOT resolve (user already cancelled once)."); shouldResolve = false; } else if (cancellations < mMaxAutoSignInAttempts) { debugLog( "onConnectionFailed: WILL resolve because we have below the max# of " + "attempts, " + cancellations + " < " + mMaxAutoSignInAttempts); shouldResolve = true; } else { shouldResolve = false; debugLog( "onConnectionFailed: Will NOT resolve; not user-initiated and max attempts " + "reached: " + cancellations + " >= " + mMaxAutoSignInAttempts); } if (!shouldResolve) { // Fail and wait for the user to want to sign in. debugLog("onConnectionFailed: since we won't resolve, failing now."); mConnectionResult = result; mConnecting = false; notifyListener(false); return; } debugLog("onConnectionFailed: resolving problem..."); // Resolve the connection result. This usually means showing a dialog or // starting an Activity that will allow the user to give the appropriate // consents so that sign-in can be successful. resolveConnectionResult(); }
/** Shows an error dialog that's appropriate for the failure reason. */ public static void showFailureDialog(Activity activity, int actResp, int errorCode) { if (activity == null) { Log.e("GameHelper", "*** No Activity. Can't show failure dialog!"); return; } Dialog errorDialog = null; switch (actResp) { case GamesActivityResultCodes.RESULT_APP_MISCONFIGURED: errorDialog = makeSimpleDialog( activity, GameHelperUtils.getString(activity, GameHelperUtils.R_APP_MISCONFIGURED)); break; case GamesActivityResultCodes.RESULT_SIGN_IN_FAILED: errorDialog = makeSimpleDialog( activity, GameHelperUtils.getString(activity, GameHelperUtils.R_SIGN_IN_FAILED)); break; case GamesActivityResultCodes.RESULT_LICENSE_FAILED: errorDialog = makeSimpleDialog( activity, GameHelperUtils.getString(activity, GameHelperUtils.R_LICENSE_FAILED)); break; default: // No meaningful Activity response code, so generate default Google // Play services dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode, activity, RC_UNUSED, null); if (errorDialog == null) { // get fallback dialog Log.e("GameHelper", "No standard error dialog available. Making fallback dialog."); errorDialog = makeSimpleDialog( activity, GameHelperUtils.getString(activity, GameHelperUtils.R_UNKNOWN_ERROR) + " " + GameHelperUtils.errorCodeToString(errorCode)); } } errorDialog.show(); }