Java Code Examples for com.google.android.gms.common.ConnectionResult#getErrorCode()
The following examples show how to use
com.google.android.gms.common.ConnectionResult#getErrorCode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Client.java From godot-gpgs with MIT License | 6 votes |
public boolean resolveConnectionFailure(ConnectionResult result, int requestCode) { if (result.hasResolution()) { try { result.startResolutionForResult(activity, requestCode); return true; } catch (IntentSender.SendIntentException e) { // The intent was canceled before it was sent. Return to the default // state and attempt to connect to get an updated ConnectionResult. googleApiClient.connect(); return false; } } else { // not resolvable... so show an error message int errorCode = result.getErrorCode(); if (errorCode == ConnectionResult.INTERNAL_ERROR) { googleApiClient.connect(); } GodotLib.calldeferred(instance_id, "_on_google_play_game_services_connection_failed", new Object[] { }); Log.i(TAG, "GPGS: onConnectionFailed error code: " + String.valueOf(errorCode)); return false; } }
Example 2
Source File: MainActivity.java From android-google-accounts with Apache License 2.0 | 6 votes |
/** * Called when the Activity could not connect to Google Play services AND the auto manager * could not resolve the error automatically. * * @param result can be inspected to determine the cause of the failure */ @Override public void onConnectionFailed(ConnectionResult result) { // Refer to the javadoc for ConnectionResult to see what error codes might be returned in // onConnectionFailed. Since this is the AutoManage sample only unresolvable errors // are returned here. Log.i(TAG, "onConnectionFailed: ConnectionResult.getErrorCode() = " + result.getErrorCode()); if (result.getErrorCode() == ConnectionResult.API_UNAVAILABLE) { // An API requested for GoogleApiClient is not available. The device's current // configuration might not be supported with the requested API or a required component // may not be installed, such as the Android Wear application. You may need to use a // second GoogleApiClient to manage the application's optional APIs. Log.i(TAG, "onConnectionFailed because an API was unavailable"); } googleApiClientConnectionStateChange(false); }
Example 3
Source File: MainActivity.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
@Override public void onConnectionFailed(ConnectionResult connectionResult) { mInProgress = false; // If the error has a resolution, start a Google Play services activity to resolve it. if (connectionResult.hasResolution()) { try { connectionResult.startResolutionForResult(this, CONNECTION_FAILURE_RESOLUTION_REQUEST); } catch (IntentSender.SendIntentException e) { Log.e(TAG, "Exception while resolving connection error.", e); } } else { int errorCode = connectionResult.getErrorCode(); Log.e(TAG, "Connection to Google Play services failed with error code " + errorCode); } }
Example 4
Source File: GacFragment.java From easygoogle with Apache License 2.0 | 6 votes |
private void showErrorDialog(ConnectionResult connectionResult) { int errorCode = connectionResult.getErrorCode(); if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) { // Show the default Google Play services error dialog which may still start an intent // on our behalf if the user can resolve the issue. GooglePlayServicesUtil.getErrorDialog(errorCode, getActivity(), mResolutionCode, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mShouldResolve = false; } }).show(); } else { // No default Google Play Services error, display a message to the user. String errorString = getString(R.string.play_services_error_fmt, errorCode); Toast.makeText(getActivity(), errorString, Toast.LENGTH_SHORT).show(); mShouldResolve = false; } }
Example 5
Source File: BaseGameUtils.java From android with Apache License 2.0 | 6 votes |
/** * Resolve a connection failure from {@link GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(ConnectionResult)} * * @param activity the Activity trying to resolve the connection failure. * @param client the GoogleAPIClient instance of the Activity. * @param result the ConnectionResult received by the Activity. * @param requestCode a request code which the calling Activity can use to identify the * result of this resolution in onActivityResult. * @param fallbackErrorMessage a generic error message to display if the failure cannot be * resolved. * @return true if the connection failure is resolved, false otherwise. */ public static boolean resolveConnectionFailure(Activity activity, GoogleApiClient client, ConnectionResult result, int requestCode, String fallbackErrorMessage) { if (result.hasResolution()) { try { result.startResolutionForResult(activity, requestCode); return true; } catch (IntentSender.SendIntentException e) { // The intent was canceled before it was sent. Return to the default // state and attempt to connect to get an updated ConnectionResult. client.connect(); return false; } } else { // not resolvable... so show an error message int errorCode = result.getErrorCode(); Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode, activity, requestCode); if (dialog != null) { dialog.show(); } else { // no built-in dialog: show the fallback error message showAlert(activity, fallbackErrorMessage); } return false; } }
Example 6
Source File: BaseGameUtils.java From 8bitartist with Apache License 2.0 | 5 votes |
/** * Resolve a connection failure from * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)} * * @param activity the Activity trying to resolve the connection failure. * @param client the GoogleAPIClient instance of the Activity. * @param result the ConnectionResult received by the Activity. * @param requestCode a request code which the calling Activity can use to identify the result * of this resolution in onActivityResult. * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved. * @return true if the connection failure is resolved, false otherwise. */ public static boolean resolveConnectionFailure(Activity activity, GoogleApiClient client, ConnectionResult result, int requestCode, String fallbackErrorMessage) { if (result.hasResolution()) { try { result.startResolutionForResult(activity, requestCode); return true; } catch (IntentSender.SendIntentException e) { // The intent was canceled before it was sent. Return to the default // state and attempt to connect to get an updated ConnectionResult. client.connect(); return false; } } else { // not resolvable... so show an error message int errorCode = result.getErrorCode(); Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode, activity, requestCode); if (dialog != null) { dialog.show(); } else { // no built-in dialog: show the fallback error message showAlert(activity, fallbackErrorMessage); } return false; } }
Example 7
Source File: GooglePlay.java From ExtensionsPack with MIT License | 5 votes |
public void onConnectionFailed(ConnectionResult result) { try { GooglePlay.result = result.getErrorCode(); if(GooglePlay.result == ConnectionResult.SIGN_IN_REQUIRED) { Log.i("trace", what + ": GooglePlayCallback: SignIn Required"); if(what == "GAMES_CLIENT") { result.startResolutionForResult(GameActivity.getInstance(), GooglePlay.GOOGLE_PLAY_SIGN_IN_REQUEST); } else if(what == "APP_STATE_CLIENT") { result.startResolutionForResult(GameActivity.getInstance(), GooglePlay.GOOGLE_PLAY_APP_STATE_SIGN_IN_REQUEST); } } else { Log.i("trace", what + ": GooglePlayCallback.onConnectionFailed: " + GooglePlay.result); } } catch(Exception e) { Log.i("trace", what + ": GooglePlayCallback.onConnectionFailed: " + e.toString()); if(GooglePlay.connectionCallback != null) { GooglePlay.connectionCallback.call("onException", new Object[] {e.toString(), "onConnectionFailed"}); } } }
Example 8
Source File: BaseGameUtils.java From FlappyCow with MIT License | 5 votes |
/** * Resolve a connection failure from * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)} * * @param activity the Activity trying to resolve the connection failure. * @param client the GoogleAPIClient instance of the Activity. * @param result the ConnectionResult received by the Activity. * @param requestCode a request code which the calling Activity can use to identify the result * of this resolution in onActivityResult. * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved. * @return true if the connection failure is resolved, false otherwise. */ public static boolean resolveConnectionFailure(Activity activity, GoogleApiClient client, ConnectionResult result, int requestCode, String fallbackErrorMessage) { if (result.hasResolution()) { try { result.startResolutionForResult(activity, requestCode); return true; } catch (IntentSender.SendIntentException e) { // The intent was canceled before it was sent. Return to the default // state and attempt to connect to get an updated ConnectionResult. client.connect(); return false; } } else { // not resolvable... so show an error message int errorCode = result.getErrorCode(); Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode, activity, requestCode); if (dialog != null) { dialog.show(); } else { // no built-in dialog: show the fallback error message showAlert(activity, fallbackErrorMessage); } return false; } }
Example 9
Source File: BaseGameUtils.java From Onesearch with MIT License | 5 votes |
/** * Resolve a connection failure from * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)} * * @param activity the Activity trying to resolve the connection failure. * @param client the GoogleAPIClient instance of the Activity. * @param result the ConnectionResult received by the Activity. * @param requestCode a request code which the calling Activity can use to identify the result * of this resolution in onActivityResult. * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved. * @return true if the connection failure is resolved, false otherwise. */ public static boolean resolveConnectionFailure(Activity activity, GoogleApiClient client, ConnectionResult result, int requestCode, String fallbackErrorMessage) { if (result.hasResolution()) { try { result.startResolutionForResult(activity, requestCode); return true; } catch (IntentSender.SendIntentException e) { // The intent was canceled before it was sent. Return to the default // state and attempt to connect to get an updated ConnectionResult. client.connect(); return false; } } else { // not resolvable... so show an error message int errorCode = result.getErrorCode(); Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode, activity, requestCode); if (dialog != null) { dialog.show(); } else { // no built-in dialog: show the fallback error message showAlert(activity, fallbackErrorMessage); } return false; } }
Example 10
Source File: MainActivity.java From android-google-accounts with Apache License 2.0 | 5 votes |
/** * Called when the Activity could not connect to Google Play services. The callback indicates * that the user needs to select an account, grant permissions, or resolve an error in order * to sign in. * * @param result can be inspected to determine the cause of the failure */ @Override public void onConnectionFailed(ConnectionResult result) { // Refer to the javadoc for ConnectionResult to see what error codes might be returned in // onConnectionFailed. Log.i(TAG, "onConnectionFailed: ConnectionResult.getErrorCode() = " + result.getErrorCode()); if (result.getErrorCode() == ConnectionResult.API_UNAVAILABLE) { // An API requested for GoogleApiClient is not available. The device's current // configuration might not be supported with the requested API or a required component // may not be installed, such as the Android Wear application. You may need to use a // second GoogleApiClient to manage the application's optional APIs. } else if (mSignInProgress != STATE_IN_PROGRESS) { // We do not have an intent in progress so we should store the latest error // resolution intent for use when the sign in button is clicked. mSignInIntent = result.getResolution(); mSignInError = result.getErrorCode(); if (mSignInProgress == STATE_SIGN_IN) { // STATE_SIGN_IN indicates the user already clicked the sign in button so we // should continue processing errors until the user is signed in or they click // cancel. resolveSignInError(); } } // In this sample we consider the user signed out when they do not have a connection to // Google Play services. onSignedOut(); }
Example 11
Source File: MainActivity.java From android-Geofencing with Apache License 2.0 | 5 votes |
@Override public void onConnectionFailed(ConnectionResult connectionResult) { // If the error has a resolution, start a Google Play services activity to resolve it. if (connectionResult.hasResolution()) { try { connectionResult.startResolutionForResult(this, CONNECTION_FAILURE_RESOLUTION_REQUEST); } catch (IntentSender.SendIntentException e) { Log.e(TAG, "Exception while resolving connection error.", e); } } else { int errorCode = connectionResult.getErrorCode(); Log.e(TAG, "Connection to Google Play services failed with error code " + errorCode); } }
Example 12
Source File: BaseGameUtils.java From 8bitartist with Apache License 2.0 | 5 votes |
/** * Resolve a connection failure from * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)} * * @param activity the Activity trying to resolve the connection failure. * @param client the GoogleAPIClient instance of the Activity. * @param result the ConnectionResult received by the Activity. * @param requestCode a request code which the calling Activity can use to identify the result * of this resolution in onActivityResult. * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved. * @return true if the connection failure is resolved, false otherwise. */ public static boolean resolveConnectionFailure(Activity activity, GoogleApiClient client, ConnectionResult result, int requestCode, String fallbackErrorMessage) { if (result.hasResolution()) { try { result.startResolutionForResult(activity, requestCode); return true; } catch (IntentSender.SendIntentException e) { // The intent was canceled before it was sent. Return to the default // state and attempt to connect to get an updated ConnectionResult. client.connect(); return false; } } else { // not resolvable... so show an error message int errorCode = result.getErrorCode(); Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode, activity, requestCode); if (dialog != null) { dialog.show(); } else { // no built-in dialog: show the fallback error message showAlert(activity, fallbackErrorMessage); } return false; } }
Example 13
Source File: FriendlyPingActivity.java From friendlyping with Apache License 2.0 | 5 votes |
private void showErrorDialog(ConnectionResult connectionResult) { final int errorCode = connectionResult.getErrorCode(); if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) { // Show the default Google Play services error dialog which may still start an // intent on our behalf if the user can resolve the issue. GooglePlayServicesUtil.getErrorDialog(errorCode, FriendlyPingActivity.this, REQUEST_CODE_SIGN_IN, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mShouldResolve = false; // For simplicity reasons we just finish the activity. // In a real world app you should deal with failing properly. Log.i(TAG, "Could not resolve issue with code: " + errorCode); finish(); } }).show(); } else { // No default Google Play Services error, display a Toast Toast.makeText(FriendlyPingActivity.this, getString(R.string.play_services_error_fmt, errorCode), Toast.LENGTH_SHORT) .show(); mShouldResolve = false; // For simplicity reasons we just finish the activity. // In a real world app you should deal with failing properly. Log.i(TAG, "Could not resolve issue with code: " + errorCode); finish(); } }
Example 14
Source File: BaseGameUtils.java From FixMath with Apache License 2.0 | 5 votes |
/** * Resolve a connection failure from * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)} * * @param activity the Activity trying to resolve the connection failure. * @param client the GoogleAPIClient instance of the Activity. * @param result the ConnectionResult received by the Activity. * @param requestCode a request code which the calling Activity can use to identify the result * of this resolution in onActivityResult. * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved. * @return true if the connection failure is resolved, false otherwise. */ public static boolean resolveConnectionFailure(Activity activity, GoogleApiClient client, ConnectionResult result, int requestCode, String fallbackErrorMessage) { if (result.hasResolution()) { try { result.startResolutionForResult(activity, requestCode); return true; } catch (IntentSender.SendIntentException e) { // The intent was canceled before it was sent. Return to the default // state and attempt to connect to get an updated ConnectionResult. client.connect(); return false; } } else { // not resolvable... so show an error message int errorCode = result.getErrorCode(); Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode, activity, requestCode); if (dialog != null) { dialog.show(); } else { // no built-in dialog: show the fallback error message showAlert(activity, fallbackErrorMessage); } return false; } }
Example 15
Source File: GoogleApiMessenger.java From Sensor-Data-Logger with Apache License 2.0 | 5 votes |
@Override public void onConnectionFailed(ConnectionResult connectionResult) { if (connectionResult.getErrorCode() == ConnectionResult.API_UNAVAILABLE) { wearableApiAvailable = false; } status.setConnected(false); status.updated(statusUpdateHandler); Log.e(TAG, "Google API client connection failed: " + connectionResult.getErrorMessage()); }
Example 16
Source File: AwarenessImpl.java From Myna with Apache License 2.0 | 5 votes |
@Override public void onConnectionFailed(@NonNull ConnectionResult result) { // Refer to the javadoc for ConnectionResult to see what error codes might be returned in // onConnectionFailed. Log.i(Utils.TAG, "Connection failed: ConnectionResult.getErrorCode() = " + result.getErrorCode()); Log.i(Utils.TAG, "Connection failed: ConnectionResult.getErrorMessage() = " + result.getErrorMessage()); MynaResult m_result = new MynaResult(result.getErrorCode(), result.getErrorMessage()); initCallback.onFailed(m_result); }
Example 17
Source File: BaseGameUtils.java From Trivia-Knowledge with Apache License 2.0 | 5 votes |
/** * Resolve a connection failure from * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)} * * @param activity the Activity trying to resolve the connection failure. * @param client the GoogleAPIClient instance of the Activity. * @param result the ConnectionResult received by the Activity. * @param requestCode a request code which the calling Activity can use to identify the result * of this resolution in onActivityResult. * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved. * @return true if the connection failure is resolved, false otherwise. */ public static boolean resolveConnectionFailure(Activity activity, GoogleApiClient client, ConnectionResult result, int requestCode, int fallbackErrorMessage) { if (result.hasResolution()) { try { result.startResolutionForResult(activity, requestCode); return true; } catch (IntentSender.SendIntentException e) { // The intent was canceled before it was sent. Return to the default // state and attempt to connect to get an updated ConnectionResult. client.connect(); return false; } } else { // not resolvable... so show an error message int errorCode = result.getErrorCode(); Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode, activity, requestCode); if (dialog != null) { dialog.show(); } else { // no built-in dialog: show the fallback error message showAlert(activity, activity.getString(fallbackErrorMessage)); } return false; } }
Example 18
Source File: BaseGameUtils.java From Asteroid with Apache License 2.0 | 5 votes |
/** * Resolve a connection failure from * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)} * * @param activity the Activity trying to resolve the connection failure. * @param client the GoogleAPIClient instance of the Activity. * @param result the ConnectionResult received by the Activity. * @param requestCode a request code which the calling Activity can use to identify the result * of this resolution in onActivityResult. * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved. * @return true if the connection failure is resolved, false otherwise. */ public static boolean resolveConnectionFailure(AppCompatActivity activity, GoogleApiClient client, ConnectionResult result, int requestCode, int fallbackErrorMessage) { if (result.hasResolution()) { try { result.startResolutionForResult(activity, requestCode); return true; } catch (IntentSender.SendIntentException e) { // The intent was canceled before it was sent. Return to the default // state and attempt to connect to get an updated ConnectionResult. client.connect(); return false; } } else { // not resolvable... so show an error message int errorCode = result.getErrorCode(); Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode, activity, requestCode); if (dialog != null) { dialog.show(); } else { // no built-in dialog: show the fallback error message showAlert(activity, activity.getString(fallbackErrorMessage)); } return false; } }
Example 19
Source File: BaseGameUtils.java From gdx-gamesvcs with Apache License 2.0 | 5 votes |
/** * Resolve a connection failure from * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)} * * @param activity the Activity trying to resolve the connection failure. * @param client the GoogleAPIClient instance of the Activity. * @param result the ConnectionResult received by the Activity. * @param requestCode a request code which the calling Activity can use to identify the result * of this resolution in onActivityResult. * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved. * @return true if the connection failure is resolved, false otherwise. */ public static boolean resolveConnectionFailure(Activity activity, GoogleApiClient client, ConnectionResult result, int requestCode, String fallbackErrorMessage) { if (result.hasResolution()) { try { result.startResolutionForResult(activity, requestCode); return true; } catch (IntentSender.SendIntentException e) { // The intent was canceled before it was sent. Return to the default // state and attempt to connect to get an updated ConnectionResult. client.connect(); return false; } } else { // not resolvable... so show an error message int errorCode = result.getErrorCode(); Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode, activity, requestCode); if (dialog != null) { dialog.show(); } else { // no built-in dialog: show the fallback error message showAlert(activity, fallbackErrorMessage); } return false; } }
Example 20
Source File: GpgsClient.java From gdx-gamesvcs with Apache License 2.0 | 4 votes |
@Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { if (mResolvingConnectionFailure) { // already resolving return; } Gdx.app.log(GAMESERVICE_ID, "onConnectFailed: " + connectionResult.getErrorCode()); boolean isPendingBefore = isConnectionPending; // if the sign-in button was clicked // launch the sign-in flow if (mSignInClicked) { mAutoStartSignInflow = false; mSignInClicked = false; mResolvingConnectionFailure = true; // Attempt to resolve the connection failure using BaseGameUtils. // The R.string.signin_other_error value should reference a generic // error string in your strings.xml file, such as "There was // an issue with sign-in, please try again later." if (!BaseGameUtils.resolveConnectionFailure(myContext, mGoogleApiClient, connectionResult, RC_GPGS_SIGNIN, "Unable to sign in.")) { mResolvingConnectionFailure = false; isConnectionPending = false; } } // Error code 4 is thrown sometimes on first attempt when game state feature is enabled. // Just retry some times solves the problem. else if (firstConnectAttempt > 0 && connectionResult.getErrorCode() == 4) { firstConnectAttempt -= 1; Gdx.app.log(GAMESERVICE_ID, "Retrying to connect..."); AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { // wait some time before next try Thread.sleep(200); if (!mGoogleApiClient.isConnected()) mGoogleApiClient.connect(); } catch (InterruptedException e) { //eat } return null; } }; task.execute(); } else isConnectionPending = false; // inform listener that connection attempt failed if (gameListener != null && isPendingBefore && !isConnectionPending) gameListener.gsOnSessionInactive(); }