Search in sources :

Example 6 with ResolvableApiException

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())));
        }
    });
}
Also used : ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) PendingIntentRequiredException(com.firebase.ui.auth.data.model.PendingIntentRequiredException)

Example 7 with ResolvableApiException

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;
                }
            }
        }
    });
}
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 8 with ResolvableApiException

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;
                }
            }
        }
    });
}
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 9 with ResolvableApiException

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;
                }
            }
        }
    });
}
Also used : ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) LocationRequest(com.google.android.gms.location.LocationRequest) LocationSettingsResponse(com.google.android.gms.location.LocationSettingsResponse) LocationSettingsRequest(com.google.android.gms.location.LocationSettingsRequest) IntentSender(android.content.IntentSender) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) ApiException(com.google.android.gms.common.api.ApiException)

Example 10 with ResolvableApiException

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();
        }
    });
}
Also used : ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) LocationSettingsResponse(com.google.android.gms.location.LocationSettingsResponse) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) ApiException(com.google.android.gms.common.api.ApiException)

Aggregations

ResolvableApiException (com.google.android.gms.common.api.ResolvableApiException)13 ApiException (com.google.android.gms.common.api.ApiException)10 LocationSettingsResponse (com.google.android.gms.location.LocationSettingsResponse)10 LocationSettingsRequest (com.google.android.gms.location.LocationSettingsRequest)6 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)6 LocationRequest (com.google.android.gms.location.LocationRequest)5 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)5 IntentSender (android.content.IntentSender)4 PendingIntentRequiredException (com.firebase.ui.auth.data.model.PendingIntentRequiredException)3 SettingsClient (com.google.android.gms.location.SettingsClient)3 Resource (com.firebase.ui.auth.data.model.Resource)2 Credential (com.google.android.gms.auth.api.credentials.Credential)2 Activity (android.app.Activity)1 Application (android.app.Application)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 TextUtils (android.text.TextUtils)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 AuthUI (com.firebase.ui.auth.AuthUI)1