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();
}
}
}
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();
}
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);
}
}
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;
}
}
});
}
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;
}
});
}
Aggregations