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());
}
}
});
}
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;
});
}
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;
}
}
}
});
}
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;
}
}
}
});
}
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);
}
}
Aggregations