Search in sources :

Example 16 with ApiException

use of com.google.android.gms.common.api.ApiException in project google-services by googlesamples.

the class IdTokenActivity method handleSignInResult.

// [START handle_sign_in_result]
private void handleSignInResult(@NonNull Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);
        String idToken = account.getIdToken();
        // TODO(developer): send ID Token to server and validate
        updateUI(account);
    } catch (ApiException e) {
        Log.w(TAG, "handleSignInResult:error", e);
        updateUI(null);
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ApiException(com.google.android.gms.common.api.ApiException)

Example 17 with ApiException

use of com.google.android.gms.common.api.ApiException in project google-services by googlesamples.

the class SignInActivity method handleSignInResult.

// [END onActivityResult]
// [START 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(TAG, "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 18 with ApiException

use of com.google.android.gms.common.api.ApiException in project google-services by googlesamples.

the class SignInActivityWithDrive method handleSignInResult.

// [END onActivityResult]
// [START handleSignInResult]
private void handleSignInResult(@Nullable Task<GoogleSignInAccount> completedTask) {
    Log.d(TAG, "handleSignInResult:" + completedTask.isSuccessful());
    try {
        // Signed in successfully, show authenticated U
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);
        updateUI(account);
    } catch (ApiException e) {
        // Signed out, show unauthenticated UI.
        Log.w(TAG, "handleSignInResult:error", e);
        updateUI(null);
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ApiException(com.google.android.gms.common.api.ApiException)

Example 19 with ApiException

use of com.google.android.gms.common.api.ApiException in project Precisely by Pankaj-Baranwal.

the class SignUp method handleSignInResult.

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);
        Constants.user_name = account.getDisplayName();
        submitData(account.getId());
    } catch (ApiException e) {
        Toast.makeText(this, "Google behaving weirdly!", Toast.LENGTH_SHORT).show();
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ApiException(com.google.android.gms.common.api.ApiException)

Example 20 with ApiException

use of com.google.android.gms.common.api.ApiException 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)

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