Search in sources :

Example 11 with ApiException

use of com.google.android.gms.common.api.ApiException in project xabber-android by redsolution.

the class XabberLoginActivity method getCaptchaToken.

/**
 * CAPTCHA
 */
private void getCaptchaToken(final SignUpRepo signUpRepo) {
    SafetyNet.getClient(this).verifyWithRecaptcha(getString(R.string.RECAPTCHA_KEY)).addOnSuccessListener(this, new OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse>() {

        @Override
        public void onSuccess(SafetyNetApi.RecaptchaTokenResponse response) {
            // Indicates communication with reCAPTCHA service was
            // successful.
            String userResponseToken = response.getTokenResult();
            if (!userResponseToken.isEmpty()) {
                // Validate the user response token using the
                // reCAPTCHA siteverify API.
                Log.d(CAPTCHA_TOKEN, "Success: " + userResponseToken);
                signUpRepo.setCaptchaToken(userResponseToken);
                signUp(signUpRepo);
            }
        }
    }).addOnFailureListener(this, new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            if (e instanceof ApiException) {
                // An error occurred when communicating with the
                // reCAPTCHA service. Refer to the status code to
                // handle the error appropriately.
                ApiException apiException = (ApiException) e;
                int statusCode = apiException.getStatusCode();
                Log.d(CAPTCHA_TOKEN, "Error: " + CommonStatusCodes.getStatusCodeString(statusCode));
            } else {
                // A different, unknown type of error occurred.
                Log.d(CAPTCHA_TOKEN, "Error: " + e.getMessage());
            }
        }
    });
}
Also used : SafetyNetApi(com.google.android.gms.safetynet.SafetyNetApi) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) SocketTimeoutException(java.net.SocketTimeoutException) ApiException(com.google.android.gms.common.api.ApiException) ApiException(com.google.android.gms.common.api.ApiException)

Example 12 with ApiException

use of com.google.android.gms.common.api.ApiException in project FirebaseUI-Android by firebase.

the class AuthUI method signOut.

/**
 * Signs the current user out, if one is signed in.
 *
 * @param context the context requesting the user be signed out
 * @return A task which, upon completion, signals that the user has been signed out ({@link
 * Task#isSuccessful()}, or that the sign-out attempt failed unexpectedly !{@link
 * Task#isSuccessful()}).
 */
@NonNull
public Task<Void> signOut(@NonNull Context context) {
    boolean playServicesAvailable = GoogleApiUtils.isPlayServicesAvailable(context);
    if (!playServicesAvailable) {
        Log.w(TAG, "Google Play services not available during signOut");
    }
    Task<Void> maybeDisableAutoSignIn = playServicesAvailable ? GoogleApiUtils.getCredentialsClient(context).disableAutoSignIn() : Tasks.forResult((Void) null);
    maybeDisableAutoSignIn.continueWith(task -> {
        // We want to ignore a specific exception, since it's not a good reason
        // to fail (see Issue 1156).
        Exception e = task.getException();
        if (e instanceof ApiException && ((ApiException) e).getStatusCode() == CommonStatusCodes.CANCELED) {
            Log.w(TAG, "Could not disable auto-sign in, maybe there are no " + "SmartLock accounts available?", e);
            return null;
        }
        return task.getResult();
    });
    return Tasks.whenAll(signOutIdps(context), maybeDisableAutoSignIn).continueWith(task -> {
        // Propagate exceptions
        task.getResult();
        mAuth.signOut();
        return null;
    });
}
Also used : ApiException(com.google.android.gms.common.api.ApiException) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) ApiException(com.google.android.gms.common.api.ApiException) NonNull(androidx.annotation.NonNull)

Example 13 with ApiException

use of com.google.android.gms.common.api.ApiException in project IITB-App by wncc.

the class FileComplaintFragment method displayLocationSettingsRequest.

private void displayLocationSettingsRequest() {
    if (getView() == null || getActivity() == null)
        return;
    LocationRequest mLocationRequest = LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(10 * 1000).setFastestInterval(1 * 1000);
    LocationSettingsRequest.Builder settingsBuilder = new LocationSettingsRequest.Builder().addLocationRequest(mLocationRequest);
    settingsBuilder.setAlwaysShow(true);
    Task<LocationSettingsResponse> result = LocationServices.getSettingsClient(getActivity()).checkLocationSettings(settingsBuilder.build());
    result.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {

        @Override
        public void onComplete(@NonNull Task<LocationSettingsResponse> task) {
            try {
                LocationSettingsResponse result = task.getResult(ApiException.class);
                if (result.getLocationSettingsStates().isGpsPresent() && result.getLocationSettingsStates().isGpsUsable() && result.getLocationSettingsStates().isLocationPresent() && result.getLocationSettingsStates().isLocationUsable()) {
                    setupGPS();
                }
            } catch (ApiException ex) {
                switch(ex.getStatusCode()) {
                    case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                        try {
                            ResolvableApiException resolvableApiException = (ResolvableApiException) ex;
                            resolvableApiException.startResolutionForResult(getActivity(), 87);
                            setupGPS();
                        } catch (IntentSender.SendIntentException e) {
                        }
                        break;
                    case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                        Toast.makeText(getContext(), getString(R.string.GPS_not_enables), Toast.LENGTH_LONG).show();
                        break;
                    default:
                        Toast.makeText(getContext(), getString(R.string.GPS_not_enables), Toast.LENGTH_LONG).show();
                        break;
                }
            }
        }
    });
}
Also used : ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) LocationRequest(com.google.android.gms.location.LocationRequest) LocationSettingsRequest(com.google.android.gms.location.LocationSettingsRequest) LocationSettingsResponse(com.google.android.gms.location.LocationSettingsResponse) IntentSender(android.content.IntentSender) ApiException(com.google.android.gms.common.api.ApiException) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException)

Example 14 with ApiException

use of com.google.android.gms.common.api.ApiException in project IITB-App by wncc.

the class MapFragment method displayLocationSettingsRequest.

private void displayLocationSettingsRequest(final boolean showWarning) {
    if (getView() == null || getActivity() == null)
        return;
    LocationRequest mLocationRequest = LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(10 * 1000).setFastestInterval(1 * 1000);
    LocationSettingsRequest.Builder settingsBuilder = new LocationSettingsRequest.Builder().addLocationRequest(mLocationRequest);
    settingsBuilder.setAlwaysShow(true);
    Task<LocationSettingsResponse> result = LocationServices.getSettingsClient(getActivity()).checkLocationSettings(settingsBuilder.build());
    result.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {

        @Override
        public void onComplete(@NonNull Task<LocationSettingsResponse> task) {
            try {
                LocationSettingsResponse result = task.getResult(ApiException.class);
                if (result.getLocationSettingsStates().isGpsPresent() && result.getLocationSettingsStates().isGpsUsable() && result.getLocationSettingsStates().isLocationPresent() && result.getLocationSettingsStates().isLocationUsable()) {
                    setupGPS(showWarning);
                }
            } catch (ApiException ex) {
                switch(ex.getStatusCode()) {
                    case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                        try {
                            ResolvableApiException resolvableApiException = (ResolvableApiException) ex;
                            resolvableApiException.startResolutionForResult(getActivity(), 87);
                            setupGPS(showWarning);
                        } catch (IntentSender.SendIntentException e) {
                        }
                        break;
                    case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                        Toast.makeText(getContext(), "GPS is not enabled!", Toast.LENGTH_LONG).show();
                        break;
                }
            }
        }
    });
}
Also used : ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) LocationRequest(com.google.android.gms.location.LocationRequest) LocationSettingsRequest(com.google.android.gms.location.LocationSettingsRequest) LocationSettingsResponse(com.google.android.gms.location.LocationSettingsResponse) IntentSender(android.content.IntentSender) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) ApiException(com.google.android.gms.common.api.ApiException)

Example 15 with ApiException

use of com.google.android.gms.common.api.ApiException in project UniPool by divya21raj.

the class LoginActivity method handleSignInResult.

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);
        firebaseAuthWithGoogle(account);
    // Signed in successfully, show authenticated UI.
    } 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());
        Toast.makeText(getApplicationContext(), "Ok", Toast.LENGTH_SHORT).show();
        updateUI(null);
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ApiException(com.google.android.gms.common.api.ApiException)

Aggregations

ApiException (com.google.android.gms.common.api.ApiException)28 GoogleSignInAccount (com.google.android.gms.auth.api.signin.GoogleSignInAccount)15 ResolvableApiException (com.google.android.gms.common.api.ResolvableApiException)10 LocationSettingsResponse (com.google.android.gms.location.LocationSettingsResponse)9 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)7 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)6 LocationRequest (com.google.android.gms.location.LocationRequest)5 LocationSettingsRequest (com.google.android.gms.location.LocationSettingsRequest)5 IntentSender (android.content.IntentSender)4 Intent (android.content.Intent)3 NonNull (androidx.annotation.NonNull)3 FirebaseAuthInvalidUserException (com.google.firebase.auth.FirebaseAuthInvalidUserException)3 Bundle (android.os.Bundle)2 TextUtils (android.text.TextUtils)2 Nullable (androidx.annotation.Nullable)2 UserCancellationException (com.firebase.ui.auth.data.model.UserCancellationException)2 AuthMethodPickerActivity (com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity)2 ExtraConstants (com.firebase.ui.auth.util.ExtraConstants)2 GoogleApiUtils (com.firebase.ui.auth.util.GoogleApiUtils)2 ProviderUtils (com.firebase.ui.auth.util.data.ProviderUtils)2