use of com.google.android.gms.common.api.ResolvableApiException in project FirebaseUI-Android by firebase.
the class SmartLockHandler method saveCredentials.
/**
* Initialize saving a credential.
*/
public void saveCredentials(@Nullable Credential credential) {
if (!getArguments().enableCredentials) {
setResult(Resource.forSuccess(mResponse));
return;
}
setResult(Resource.forLoading());
if (credential == null) {
setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.UNKNOWN_ERROR, "Failed to build credential.")));
return;
}
deleteUnusedCredentials();
getCredentialsClient().save(credential).addOnCompleteListener(task -> {
if (task.isSuccessful()) {
setResult(Resource.forSuccess(mResponse));
} else if (task.getException() instanceof ResolvableApiException) {
ResolvableApiException rae = (ResolvableApiException) task.getException();
setResult(Resource.forFailure(new PendingIntentRequiredException(rae.getResolution(), RequestCodes.CRED_SAVE)));
} else {
Log.w(TAG, "Non-resolvable exception: " + task.getException());
setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.UNKNOWN_ERROR, "Error when saving credential.", task.getException())));
}
});
}
use of com.google.android.gms.common.api.ResolvableApiException 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.ResolvableApiException 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.ResolvableApiException in project wiseasily by eFishery.
the class MainActivity method initLocationParameters.
private void initLocationParameters() {
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
LocationSettingsRequest locationSettingsRequest = builder.build();
Task<LocationSettingsResponse> result = LocationServices.getSettingsClient(this).checkLocationSettings(locationSettingsRequest);
result.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {
@Override
public void onComplete(@NonNull Task<LocationSettingsResponse> task) {
try {
LocationSettingsResponse response = task.getResult(ApiException.class);
tryToConnect();
} catch (ApiException exception) {
switch(exception.getStatusCode()) {
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
try {
ResolvableApiException resolvable = (ResolvableApiException) exception;
resolvable.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
Log.d("MainActivity_Location", e.toString());
} catch (ClassCastException e) {
Log.d("MainActivity_Location", e.toString());
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
Log.d("MainActivity_Location", "LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE");
break;
}
}
}
});
}
use of com.google.android.gms.common.api.ResolvableApiException in project android-play-location by googlesamples.
the class MainActivity method startLocationUpdates.
/**
* Requests location updates from the FusedLocationApi. Note: we don't call this unless location
* runtime permission has been granted.
*/
private void startLocationUpdates() {
// Begin by checking if the device has the necessary location settings.
mSettingsClient.checkLocationSettings(mLocationSettingsRequest).addOnSuccessListener(this, new OnSuccessListener<LocationSettingsResponse>() {
@Override
public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
Log.i(TAG, "All location settings are satisfied.");
// noinspection MissingPermission
mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
updateUI();
}
}).addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
int statusCode = ((ApiException) e).getStatusCode();
switch(statusCode) {
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
Log.i(TAG, "Location settings are not satisfied. Attempting to upgrade " + "location settings ");
try {
// Show the dialog by calling startResolutionForResult(), and check the
// result in onActivityResult().
ResolvableApiException rae = (ResolvableApiException) e;
rae.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException sie) {
Log.i(TAG, "PendingIntent unable to execute request.");
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
String errorMessage = "Location settings are inadequate, and cannot be " + "fixed here. Fix in Settings.";
Log.e(TAG, errorMessage);
Toast.makeText(MainActivity.this, errorMessage, Toast.LENGTH_LONG).show();
mRequestingLocationUpdates = false;
}
updateUI();
}
});
}
Aggregations