com.google.android.gms.auth.api.signin.GoogleSignInStatusCodes Java Examples

The following examples show how to use com.google.android.gms.auth.api.signin.GoogleSignInStatusCodes. 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: GoogleProviderHandler.java    From capacitor-firebase-auth with MIT License 6 votes vote down vote up
@Override
public void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(GOOGLE_TAG, "Google SignIn activity result.");

    try {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        // Google Sign In was successful, authenticate with Firebase
        GoogleSignInAccount account = task.getResult(ApiException.class);

        if (account != null) {
            Log.d(GOOGLE_TAG, "Google Sign In succeed.");
            AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
            this.plugin.handleAuthCredentials(credential);
            return;
        }
    } catch (ApiException exception) {
        // Google Sign In failed, update UI appropriately
        Log.w(GOOGLE_TAG, GoogleSignInStatusCodes.getStatusCodeString(exception.getStatusCode()), exception);
        plugin.handleFailure("Google Sign In failure.", exception);
        return;
    }

    plugin.handleFailure("Google Sign In failure.", null);
}
 
Example #2
Source File: LoadingActivity.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (requestCode == GOOGLE_SIGN_IN_CODE) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result == null) return;

        if (result.isSuccess()) {
            googleSignedIn(result.getSignInAccount());
        } else {
            if (result.getStatus().getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CANCELLED)
                Prefs.putBoolean(PK.SHOULD_PROMPT_GOOGLE_PLAY, false);

            String msg = result.getStatus().getStatusMessage();
            if (msg != null && !msg.isEmpty())
                Toaster.with(this).message(msg).show();
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example #3
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 #4
Source File: GoogleSignUpAdapter.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
@Override public Single<Account> signUp(GoogleSignInResult result, AccountService service) {

    if (!isEnabled()) {
      return Single.error(new IllegalStateException("Google sign up is not enabled"));
    }

    final GoogleSignInAccount account = result.getSignInAccount();
    if (result.isSuccess() && account != null) {
      return service.createAccount(account.getEmail(), account.getServerAuthCode(), "GOOGLE");
    } else {
      return Single.error(new GoogleSignUpException(GoogleSignInStatusCodes.getStatusCodeString(
          result.getStatus()
              .getStatusCode()), result.getStatus()
          .getStatusCode()));
    }
  }
 
Example #5
Source File: GoogleSignInActivity.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
protected void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);

        // Signed in successfully, show authenticated UI.
        updateUi(account);
    } catch (ApiException e) {
        // The ApiException status code indicates the detailed failure reason.
        // Please refer to the GoogleSignInStatusCodes class reference for more information.
        Log.w(TAG,
                "signInResult:failed code=" + e.getStatusCode() + ". Msg=" + GoogleSignInStatusCodes.getStatusCodeString(e.getStatusCode()));
        updateUi(null);
    }
}
 
Example #6
Source File: RNGoogleSigninModule.java    From google-signin with MIT License 5 votes vote down vote up
@Override
public Map<String, Object> getConstants() {
    final Map<String, Object> constants = new HashMap<>();
    constants.put("BUTTON_SIZE_ICON", SignInButton.SIZE_ICON_ONLY);
    constants.put("BUTTON_SIZE_STANDARD", SignInButton.SIZE_STANDARD);
    constants.put("BUTTON_SIZE_WIDE", SignInButton.SIZE_WIDE);
    constants.put("BUTTON_COLOR_AUTO", SignInButton.COLOR_AUTO);
    constants.put("BUTTON_COLOR_LIGHT", SignInButton.COLOR_LIGHT);
    constants.put("BUTTON_COLOR_DARK", SignInButton.COLOR_DARK);
    constants.put("SIGN_IN_CANCELLED", String.valueOf(GoogleSignInStatusCodes.SIGN_IN_CANCELLED));
    constants.put("SIGN_IN_REQUIRED", String.valueOf(CommonStatusCodes.SIGN_IN_REQUIRED));
    constants.put("IN_PROGRESS", ASYNC_OP_IN_PROGRESS);
    constants.put(PLAY_SERVICES_NOT_AVAILABLE, PLAY_SERVICES_NOT_AVAILABLE);
    return constants;
}
 
Example #7
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 #8
Source File: RNGoogleSigninModule.java    From google-signin with MIT License 5 votes vote down vote up
private void handleSignOutOrRevokeAccessTask(@NonNull Task<Void> task, final Promise promise) {
    if (task.isSuccessful()) {
        promise.resolve(null);
    } else {
        int code = getExceptionCode(task);
        String errorDescription = GoogleSignInStatusCodes.getStatusCodeString(code);
        promise.reject(String.valueOf(code), errorDescription);
    }
}
 
Example #9
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())));
        }
    }
}