use of com.google.android.gms.common.api.ApiException in project Grupp by tmoronta1208.
the class LoginActivity method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.w("TAG", "Google sign in failed", e);
Toast.makeText(this, "Auth went wrong :(", Toast.LENGTH_SHORT).show();
// ...
}
}
}
use of com.google.android.gms.common.api.ApiException in project google-services by googlesamples.
the class RestApiActivity method handleSignInResult.
private void handleSignInResult(@NonNull Task<GoogleSignInAccount> completedTask) {
Log.d(TAG, "handleSignInResult:" + completedTask.isSuccessful());
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
updateUI(account);
// Store the account from the result
mAccount = account.getAccount();
// Asynchronously access the People API for the account
getContacts();
} catch (ApiException e) {
Log.w(TAG, "handleSignInResult:error", e);
// Clear the local account
mAccount = null;
// Signed out, show unauthenticated UI.
updateUI(null);
}
}
use of com.google.android.gms.common.api.ApiException in project google-services by googlesamples.
the class ServerAuthCodeActivity method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_GET_AUTH_CODE) {
// [START get_auth_code]
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
String authCode = account.getServerAuthCode();
// Show signed-un UI
updateUI(account);
// TODO(developer): send code to server and exchange for access/refresh/ID tokens
} catch (ApiException e) {
Log.w(TAG, "Sign-in failed", e);
updateUI(null);
}
// [END get_auth_code]
}
}
use of com.google.android.gms.common.api.ApiException in project Devsfolio by Madonahs.
the class LoginActivity method handleGoogleSignInResult.
/**
* Handles google sign in result
*
* @param completedTask - completed GoogleSignInAccount task
*/
private void handleGoogleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
// Successfully signed in
if (account != null) {
// TODO: All user's basic info such as name can now be obtained from the account object
String personName = account.getDisplayName();
String personEmail = account.getEmail();
// For debugging purposes only
Log.d(TAG, "Google info " + personName + " - " + personEmail);
// Start MainActivity
Intent mainActivityIntent = new Intent(getBaseContext(), MainActivity.class);
// TODO: User info can be passed in to the MainActivity as EXTRA or stored locally in db or Firebase
startActivity(mainActivityIntent);
}
} catch (ApiException e) {
// Google sign in failed
e.printStackTrace();
}
}
use of com.google.android.gms.common.api.ApiException in project Instafood by Gear61.
the class LocationServicesManager method askForLocationServices.
void askForLocationServices(final int requestCode) {
Task<LocationSettingsResponse> result = LocationServices.getSettingsClient(activity).checkLocationSettings(locationBuilder.build());
result.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {
@Override
public void onComplete(@NonNull Task<LocationSettingsResponse> task) {
try {
task.getResult(ApiException.class);
} catch (ApiException exception) {
switch(exception.getStatusCode()) {
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
try {
ResolvableApiException resolvable = (ResolvableApiException) exception;
// Show dialog to turn on location services
resolvable.startResolutionForResult(activity, requestCode);
} catch (IntentSender.SendIntentException | ClassCastException ignored) {
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
openLocationSettings();
break;
}
}
}
});
}
Aggregations