Java Code Examples for com.google.android.gms.common.api.ApiException#getStatusCode()

The following examples show how to use com.google.android.gms.common.api.ApiException#getStatusCode() . 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: AndroidGoogleAccount.java    From QtAndroidTools with MIT License 6 votes vote down vote up
@Override
public void onComplete(@NonNull Task<GoogleSignInAccount> SignInTask)
{
    boolean signInSuccessfully = true;

    try
    {
        loadSignedInAccountInfo(SignInTask.getResult(ApiException.class));
    }
    catch(ApiException e)
    {
        switch(e.getStatusCode())
        {
            case GoogleSignInStatusCodes.DEVELOPER_ERROR:
                Log.d(TAG, "DEVELOPER_ERROR -> Have you signed your project on Android console?");
                break;
            case GoogleSignInStatusCodes.SIGN_IN_REQUIRED:
                Log.d(TAG, "SIGN_IN_REQUIRED -> You have to signin by select account before use this call");
                break;
        }
        signInSuccessfully = false;
        mGoogleSignInClient = null;
    }

    signedIn(signInSuccessfully);
}
 
Example 2
Source File: RNGoogleSigninModule.java    From google-signin with MIT License 5 votes vote down vote up
private void handleSignInTaskResult(Task<GoogleSignInAccount> result) {
    try {
        GoogleSignInAccount account = result.getResult(ApiException.class);
        if (account == null) {
            promiseWrapper.reject(MODULE_NAME, "GoogleSignInAccount instance was null");
        } else {
            WritableMap userParams = getUserProperties(account);
            promiseWrapper.resolve(userParams);
        }
    } catch (ApiException e) {
        int code = e.getStatusCode();
        String errorDescription = GoogleSignInStatusCodes.getStatusCodeString(code);
        promiseWrapper.reject(String.valueOf(code), errorDescription);
    }
}
 
Example 3
Source File: Utils.java    From google-signin with MIT License 5 votes vote down vote up
public static int getExceptionCode(@NonNull Task<Void> task) {
    Exception e = task.getException();

    if (e instanceof ApiException) {
        ApiException exception = (ApiException) e;
        return exception.getStatusCode();
    }
    return CommonStatusCodes.INTERNAL_ERROR;
}
 
Example 4
Source File: GoogleSignInHandler.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (requestCode != RequestCodes.GOOGLE_PROVIDER) { return; }

    try {
        GoogleSignInAccount account = GoogleSignIn.getSignedInAccountFromIntent(data)
                .getResult(ApiException.class);
        setResult(Resource.forSuccess(createIdpResponse(account)));
    } catch (ApiException e) {
        if (e.getStatusCode() == CommonStatusCodes.INVALID_ACCOUNT) {
            // If we get INVALID_ACCOUNT, it means the pre-set account was not available on the
            // device so set the email to null and launch the sign-in picker.
            mEmail = null;
            start();
        } else if (e.getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CURRENTLY_IN_PROGRESS) {
            // Hack for https://github.com/googlesamples/google-services/issues/345
            // Google remembers the account so the picker doesn't appear twice for the user.
            start();
        } else if (e.getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CANCELLED) {
            setResult(Resource.<IdpResponse>forFailure(new UserCancellationException()));
        } else {
            if (e.getStatusCode() == CommonStatusCodes.DEVELOPER_ERROR) {
                Log.w(TAG, "Developer error: this application is misconfigured. " +
                        "Check your SHA1 and package name in the Firebase console.");
            }
            setResult(Resource.<IdpResponse>forFailure(new FirebaseUiException(
                    ErrorCodes.PROVIDER_ERROR,
                    "Code: " + e.getStatusCode() + ", message: " + e.getMessage())));
        }
    }
}
 
Example 5
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 5 votes vote down vote up
private void handleException(Exception e, String details) {
  int status = 0;

  if (e instanceof ApiException) {
    ApiException apiException = (ApiException) e;
    status = apiException.getStatusCode();
  }

  String message = getString(R.string.status_exception_error, details, status, e);

  new AlertDialog.Builder(MainActivity.this)
      .setMessage(message)
      .setNeutralButton(android.R.string.ok, null)
      .show();
}
 
Example 6
Source File: SkeletonActivity.java    From android-basic-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Since a lot of the operations use tasks, we can use a common handler for whenever one fails.
 *
 * @param exception The exception to evaluate.  Will try to display a more descriptive reason for
 *                  the exception.
 * @param details   Will display alongside the exception if you wish to provide more details for
 *                  why the exception happened
 */
private void handleException(Exception exception, String details) {
  int status = 0;

  if (exception instanceof TurnBasedMultiplayerClient.MatchOutOfDateApiException) {
    TurnBasedMultiplayerClient.MatchOutOfDateApiException matchOutOfDateApiException =
        (TurnBasedMultiplayerClient.MatchOutOfDateApiException) exception;

    new AlertDialog.Builder(this)
        .setMessage("Match was out of date, updating with latest match data...")
        .setNeutralButton(android.R.string.ok, null)
        .show();

    TurnBasedMatch match = matchOutOfDateApiException.getMatch();
    updateMatch(match);

    return;
  }

  if (exception instanceof ApiException) {
    ApiException apiException = (ApiException) exception;
    status = apiException.getStatusCode();
  }

  if (!checkStatusCode(status)) {
    return;
  }

  String message = getString(R.string.status_exception_error, details, status, exception);

  new AlertDialog.Builder(this)
      .setMessage(message)
      .setNeutralButton(android.R.string.ok, null)
      .show();
}
 
Example 7
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Since a lot of the operations use tasks, we can use a common handler for whenever one fails.
 *
 * @param exception The exception to evaluate.  Will try to display a more descriptive reason for the exception.
 * @param details   Will display alongside the exception if you wish to provide more details for why the exception
 *                  happened
 */
private void handleException(Exception exception, String details) {
  int status = 0;

  if (exception instanceof ApiException) {
    ApiException apiException = (ApiException) exception;
    status = apiException.getStatusCode();
  }

  String message = getString(R.string.status_exception_error, details, status, exception);

  new AlertDialog.Builder(MainActivity.this)
      .setMessage(message)
      .setNeutralButton(android.R.string.ok, null)
      .show();

  // Note that showing a toast is done here for debugging. Your application should
  // resolve the error appropriately to your app.
  if (status == GamesClientStatusCodes.SNAPSHOT_NOT_FOUND) {
    Log.i(TAG, "Error: Snapshot not found");
    Toast.makeText(getBaseContext(), "Error: Snapshot not found",
        Toast.LENGTH_SHORT).show();
  } else if (status == GamesClientStatusCodes.SNAPSHOT_CONTENTS_UNAVAILABLE) {
    Log.i(TAG, "Error: Snapshot contents unavailable");
    Toast.makeText(getBaseContext(), "Error: Snapshot contents unavailable",
        Toast.LENGTH_SHORT).show();
  } else if (status == GamesClientStatusCodes.SNAPSHOT_FOLDER_UNAVAILABLE) {
    Log.i(TAG, "Error: Snapshot folder unavailable");
    Toast.makeText(getBaseContext(), "Error: Snapshot folder unavailable.",
        Toast.LENGTH_SHORT).show();
  }
}
 
Example 8
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
/**
 * Since a lot of the operations use tasks, we can use a common handler for whenever one fails.
 *
 * @param exception The exception to evaluate.  Will try to display a more descriptive reason for the exception.
 * @param details   Will display alongside the exception if you wish to provide more details for why the exception
 *                  happened
 */
private void handleException(Exception exception, String details) {
  int status = 0;

  if (exception instanceof ApiException) {
    ApiException apiException = (ApiException) exception;
    status = apiException.getStatusCode();
  }

  String errorString = null;
  switch (status) {
    case GamesCallbackStatusCodes.OK:
      break;
    case GamesClientStatusCodes.MULTIPLAYER_ERROR_NOT_TRUSTED_TESTER:
      errorString = getString(R.string.status_multiplayer_error_not_trusted_tester);
      break;
    case GamesClientStatusCodes.MATCH_ERROR_ALREADY_REMATCHED:
      errorString = getString(R.string.match_error_already_rematched);
      break;
    case GamesClientStatusCodes.NETWORK_ERROR_OPERATION_FAILED:
      errorString = getString(R.string.network_error_operation_failed);
      break;
    case GamesClientStatusCodes.INTERNAL_ERROR:
      errorString = getString(R.string.internal_error);
      break;
    case GamesClientStatusCodes.MATCH_ERROR_INACTIVE_MATCH:
      errorString = getString(R.string.match_error_inactive_match);
      break;
    case GamesClientStatusCodes.MATCH_ERROR_LOCALLY_MODIFIED:
      errorString = getString(R.string.match_error_locally_modified);
      break;
    default:
      errorString = getString(R.string.unexpected_status, GamesClientStatusCodes.getStatusCodeString(status));
      break;
  }

  if (errorString == null) {
    return;
  }

  String message = getString(R.string.status_exception_error, details, status, exception);

  new AlertDialog.Builder(MainActivity.this)
      .setTitle("Error")
      .setMessage(message + "\n" + errorString)
      .setNeutralButton(android.R.string.ok, null)
      .show();
}