Java Code Examples for com.google.android.gms.common.ConnectionResult#hasResolution()

The following examples show how to use com.google.android.gms.common.ConnectionResult#hasResolution() . 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: LoginActivity.java    From zulip-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult result) {
    if (commonProgressDialog.isShowing()) {
        // The user clicked the sign-in button already. Start to resolve
        // connection errors. Wait until onConnected() to dismiss the
        // connection dialog.
        if (result.hasResolution()) {
            try {
                result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
            } catch (SendIntentException e) {
                Log.e(TAG, e.getMessage(), e);
                // Yeah, no idea what to do here.
                commonProgressDialog.dismiss();
                Toast.makeText(LoginActivity.this, R.string.google_app_login_failed, Toast.LENGTH_SHORT).show();
            }
        } else {
            commonProgressDialog.dismiss();
            if (!isNetworkAvailable()) {
                Toast.makeText(LoginActivity.this, R.string.toast_no_internet_connection, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(LoginActivity.this, R.string.google_app_login_failed, Toast.LENGTH_SHORT).show();
            }

        }
    }
}
 
Example 2
Source File: GoogleHelper.java    From argus-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {

    if (!isResolving && shouldResolve) {
        if (connectionResult.hasResolution()) {
            try {
                connectionResult.startResolutionForResult(fragment.getActivity(), RC_SIGN_IN);
                isResolving = true;
            } catch (IntentSender.SendIntentException e) {
                isResolving = false;
                googleApiClient.connect();
            }
        } else {
            showErrorDialog(connectionResult);
        }
    }
}
 
Example 3
Source File: CloudletDemoActivity.java    From faceswap with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult result) {
    // Called whenever the API client fails to connect.
    Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
    Toast.makeText(this, "Failed to Connect to Google Drive. Trying to resolve...",
            Toast.LENGTH_SHORT).show();
    if (!result.hasResolution()) {
        // show the localized error dialog.
        GoogleApiAvailability.getInstance().getErrorDialog(this, result.getErrorCode(), 0).show();
        Log.i(TAG, "trying to resolve" + result.toString());
        pendingGDriveAction=-1;
        return;
    }

    // The failure has a resolution. Resolve it.
    // Called typically when the app is not yet authorized, and an
    // authorization
    // dialog is displayed to the user.
    try {
        result.startResolutionForResult(this, GDRIVE_RESOLVE_CONNECTION_REQUEST_CODE);
    } catch (IntentSender.SendIntentException e) {
        Log.e(TAG, "Exception while starting resolution activity", e);
    }
}
 
Example 4
Source File: DriveActivity.java    From biermacht with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult result) {
  Log.d("DriveActivity", "Google API Connection failed");
  if (result.hasResolution()) {
    Log.d("DriveActivity", "Failure has a resolution, starting");
    try {
      result.startResolutionForResult(this, Constants.REQUEST_CONNECT_TO_DRIVE);
    } catch (IntentSender.SendIntentException e) {
      driveClient.connect();
    }
  }
  else {
    Log.e("DriveActivity", "No resolution, showing error dialog");
    GoogleApiAvailability.getInstance().getErrorDialog(this, result.getErrorCode(),
                                                       Constants.REQUEST_CONNECT_TO_DRIVE).show();
  }

}
 
Example 5
Source File: MainActivity.java    From OpenCircle with GNU General Public License v3.0 6 votes vote down vote up
private void tryResolvedConnectionGPS(ConnectionResult connectionResult)
{
    if(connectionResult.hasResolution())
    {
        try
        {
            connectionResult
                    .startResolutionForResult(this, Constants.REQUEST_PLAY_SERVICES_ERROR);
        }
        catch(IntentSender.SendIntentException e)
        {
            mGoogleApiClient.connect();
        }
    }
    else
    {
        showDialogErrorPlayServices(connectionResult.getErrorCode());
    }
}
 
Example 6
Source File: WearService.java    From LibreAlarm with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult result) {
    if (mResolvingError) {
        // Already attempting to resolve an error.
        return;
    } else if (result.hasResolution() && mActivity != null) {
        try {
            mResolvingError = true;
            result.startResolutionForResult(mActivity, 1000);
        } catch (IntentSender.SendIntentException e) {
            // There was an error with the resolution intent. Try again.
            mGoogleApiClient.connect();
        }
    } else {
        Log.e(TAG, "Connection to Google API client has failed");
        mResolvingError = false;
        if (mListener != null) mListener.onDataUpdated();
        Wearable.MessageApi.removeListener(mGoogleApiClient, this);
        Wearable.DataApi.removeListener(mGoogleApiClient, this);
    }
}
 
Example 7
Source File: BaseGameUtils.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * 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 8
Source File: Main.java    From chess with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnectionFailed(final ConnectionResult connectionResult) {
    if (connectionResult.hasResolution()) {
        // This problem can be fixed. So let's try to fix it.
        try {
            // launch appropriate UI flow (which might, for example, be the
            // sign-in flow)
            connectionResult.startResolutionForResult(this, RC_RESOLVE);
        } catch (IntentSender.SendIntentException e) {
            // Try connecting again
            mGoogleApiClient.connect();
        }
    } else {
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
    }
}
 
Example 9
Source File: LocationProvider.java    From open-location-code with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    if (connectionResult.hasResolution() && mContext instanceof Activity) {
        try {
            Activity activity = (Activity) mContext;
            connectionResult.startResolutionForResult(
                activity, CONNECTION_FAILURE_RESOLUTION_REQUEST);
        } catch (IntentSender.SendIntentException e) {
            Log.e(TAG, e.getMessage());
        }
    } else {
        Log.i(
                TAG,
                "Location services connection failed with code: "
                        + connectionResult.getErrorCode());
        connectUsingOldApi();
    }
}
 
Example 10
Source File: LeanbackFragment.java    From CumulusTV with MIT License 6 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    if (DEBUG) {
        Log.d(TAG, "Error connecting " + connectionResult.getErrorCode());
        Log.d(TAG, "oCF " + connectionResult.toString());
    }
    if (connectionResult.hasResolution()) {
        try {
            connectionResult.startResolutionForResult(mActivity, ActivityUtils.RESOLVE_CONNECTION_REQUEST_CODE);
        } catch (IntentSender.SendIntentException e) {
            // Unable to resolve, message user appropriately
        }
    } else {
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), mActivity, 0).show();
    }
}
 
Example 11
Source File: BeaconsFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult result) {

    Log.v(TAG, "GoogleApiClient failed");
    if (result.hasResolution()) {
        try {
            result.startResolutionForResult(getActivity(), REQUEST_RESOLVE_ERROR);
        } catch (IntentSender.SendIntentException e) {
            e.printStackTrace();
        }
    } else {
        Log.v(TAG, "GoogleApiClient connection failed");
        updateNearbyPermissionStatus(false);
    }
}
 
Example 12
Source File: LoginActivity.java    From platform-friends-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult result) {
    if (result.hasResolution()) {
        try {
            result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
        } catch (IntentSender.SendIntentException e) {
            mPlusClient.connect();
        }
    }
    mConnectionResult = result;
}
 
Example 13
Source File: BaseGameUtils.java    From FixMath with Apache License 2.0 5 votes vote down vote up
/**
 * 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 14
Source File: LoginActivity.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onConnectionFailed(@NonNull ConnectionResult result) {
    if (result.hasResolution()) {
        try {
            result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
        } catch (IntentSender.SendIntentException ignore) {
            // The intent was canceled before it was sent.
        }
    }
}
 
Example 15
Source File: MapsActivity.java    From android-location-example with MIT License 5 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    /*
     * Google Play services can resolve some errors it detects.
     * If the error has a resolution, try sending an Intent to
     * start a Google Play services activity that can resolve
     * error.
     */
    if (connectionResult.hasResolution()) {
        try {
            // Start an Activity that tries to resolve the error
            connectionResult.startResolutionForResult(this, CONNECTION_FAILURE_RESOLUTION_REQUEST);
            /*
             * Thrown if Google Play services canceled the original
             * PendingIntent
             */
        } catch (IntentSender.SendIntentException e) {
            // Log the error
            e.printStackTrace();
        }
    } else {
        /*
         * If no resolution is available, display a dialog to the
         * user with the error.
         */
        Log.i(TAG, "Location services connection failed with code " + connectionResult.getErrorCode());
    }
}
 
Example 16
Source File: MainActivity.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    Log.d(TAG, "onConnectionFailed");

    /*
     * Google Play servicesに接続できなかった場合でも、解決策が提示される場合があります。 インテントを投げるとよしなに解決してくれます。
     */
    if (connectionResult.hasResolution()) {
        try {

            // エラーを解決してくれるインテントを投げます
            connectionResult.startResolutionForResult(this, CONNECTION_FAILURE_RESOLUTION_REQUEST);

            /*
             * 失敗することもあります
             */
        } catch (IntentSender.SendIntentException e) {

            // Log the error
            e.printStackTrace();
        }
    } else {

        // 解決策がない場合はエラーダイアログを出します
        showErrorDialog(connectionResult.getErrorCode(), CONNECTION_FAILURE_RESOLUTION_REQUEST);
    }

}
 
Example 17
Source File: BaseGameUtils.java    From 8bitartist with Apache License 2.0 5 votes vote down vote up
/**
 * 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 18
Source File: MenuListActivity.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onDriveConnectionFailed(DriveConnectionFailed event) {
    dismissProgressDialog();
    ConnectionResult connectionResult = event.connectionResult;
    if (connectionResult.hasResolution()) {
        try {
            connectionResult.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE);
        } catch (IntentSender.SendIntentException e) {
            // Unable to resolve, message user appropriately
            onDriveBackupError(new DriveBackupError(e.getMessage()));
        }
    } else {
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
    }
}
 
Example 19
Source File: BaseGameUtils.java    From gdx-gamesvcs with Apache License 2.0 5 votes vote down vote up
/**
 * 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: SearchClinics.java    From Crimson with Apache License 2.0 4 votes vote down vote up
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {


    if (connectionResult.hasResolution()) {
        try {

            connectionResult.startResolutionForResult(this, CONNECTION_FAILURE_RESOLUTION_REQUEST);

        } catch (IntentSender.SendIntentException e) {
            e.printStackTrace();
        }
    } else {

        Log.e("Error", "Location services connection failed with code " + connectionResult.getErrorCode());
    }

}