Search in sources :

Example 6 with ApiException

use of com.google.android.gms.common.api.ApiException in project Firebase-Login by jocelin09.

the class LoginActivity method onActivityResult.

/*
    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
        Toast.makeText(this, "Connection failed,Please try again later", Toast.LENGTH_SHORT).show();
    }

*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // if the requestCode is the Google Sign In code that we defined at starting
    if (requestCode == RC_SIGN_IN) {
        // Getting the GoogleSignIn Task
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);
            // authenticating with firebase
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            Toast.makeText(LoginActivity.this, "failed::" + e.toString(), Toast.LENGTH_SHORT).show();
        }
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ApiException(com.google.android.gms.common.api.ApiException)

Example 7 with ApiException

use of com.google.android.gms.common.api.ApiException in project roastd by Roastd.

the class LoginActivity method handleSignInResult.

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);
        User.setUsername(this, account.getDisplayName());
        String photoUrl;
        try {
            photoUrl = account.getPhotoUrl().toString();
        } catch (NullPointerException np) {
            Log.d("GOOGLE", "Account did not contain a photo URL.");
            // TODO: Maybe use a placeholder profile pic?
            photoUrl = "";
        }
        User.setPhotoUrl(this, photoUrl);
        User.setEmail(this, account.getEmail());
        setResult(RESULT_OK);
    } 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());
    }
    finish();
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ApiException(com.google.android.gms.common.api.ApiException)

Example 8 with ApiException

use of com.google.android.gms.common.api.ApiException in project CDT by IUS-CS.

the class SignInActivity method handleSignInResult.

private 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("SIGN_IN", "signInResult:failed code=" + e.getStatusCode());
        updateUI(null);
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ApiException(com.google.android.gms.common.api.ApiException)

Example 9 with ApiException

use of com.google.android.gms.common.api.ApiException in project NightSkyGuide by MTBehnke.

the class SettingsActivity method startLocationUpdates.

public void startLocationUpdates() {
    // if settings are satisfied initialize location requests
    mSettingsClient.checkLocationSettings(mLocationSettingsRequest).addOnSuccessListener(this, new OnSuccessListener<LocationSettingsResponse>() {

        @Override
        public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
            locUpdates = true;
            // All location settings are satisfied.
            // noinspection MissingPermission - this comment needs to stay here to stop inspection on next line
            mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
        }
    }).addOnFailureListener(this, new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            int statusCode = ((ApiException) e).getStatusCode();
            switch(statusCode) {
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    // location settings are not satisfied, but this can be fixed by showing the user a dialog.
                    try {
                        // show the dialog by calling startResolutionForResult(), and check the result in onActivityResult().
                        ResolvableApiException resolvable = (ResolvableApiException) e;
                        resolvable.startResolutionForResult(SettingsActivity.this, REQUEST_CHECK_SETTINGS);
                    } catch (IntentSender.SendIntentException sendEx) {
                    // Ignore the error
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    // location settings are not satisfied, however no way to fix the settings so don't show dialog.
                    Toast.makeText(context, "Location Services Unavailable", Toast.LENGTH_LONG).show();
                    useGPS = false;
                    SharedPreferences.Editor edit = preferences.edit();
                    edit.putBoolean("use_device_location", false);
                    edit.apply();
                    settingsFragment.useDeviceLocation.setChecked(false);
                    settingsFragment.setLocSummary();
                    break;
            }
        }
    });
}
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)

Example 10 with ApiException

use of com.google.android.gms.common.api.ApiException in project routerkeygenAndroid by routerkeygen.

the class NetworksListActivity method settingsRequest.

public static void settingsRequest(final Activity activity, OnSuccessListener cb) {
    LocationRequest mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(100000);
    mLocationRequest.setFastestInterval(50000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(mLocationRequest);
    builder.setAlwaysShow(true);
    SettingsClient client = LocationServices.getSettingsClient(activity);
    Task<LocationSettingsResponse> task = client.checkLocationSettings(builder.build());
    task.addOnSuccessListener(activity, cb);
    task.addOnFailureListener(activity, e -> {
        int statusCode = ((ApiException) e).getStatusCode();
        switch(statusCode) {
            case CommonStatusCodes.RESOLUTION_REQUIRED:
                // by showing the user a dialog.
                try {
                    // Show the dialog by calling startResolutionForResult(),
                    // and check the result in onActivityResult().
                    ResolvableApiException resolvable = (ResolvableApiException) e;
                    resolvable.startResolutionForResult(activity, REQUEST_CHECK_SETTINGS);
                } catch (IntentSender.SendIntentException sendEx) {
                // Ignore the error.
                }
                break;
            case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                // to fix the settings so we won't show the dialog.
                break;
        }
    });
}
Also used : SettingsClient(com.google.android.gms.location.SettingsClient) 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)

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