use of com.google.android.gms.auth.UserRecoverableAuthException in project AnyMemo by helloworld1.
the class GoogleAccountActivity method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result == null) {
activityComponents().errorUtil().showFatalError(getString(R.string.google_sign_in_empty_error_text), null);
return;
}
if (!result.isSuccess()) {
activityComponents().errorUtil().showFatalError(getString(R.string.google_sign_in_not_successful_error_text), null);
return;
}
GoogleSignInAccount acct = result.getSignInAccount();
if (acct == null) {
activityComponents().errorUtil().showFatalError(getString(R.string.google_sign_in_account_empty_result), null);
return;
}
// Get account information
final String email = acct.getEmail();
appComponents().executorService().submit(new Runnable() {
@Override
public void run() {
try {
String token = GoogleAuthUtil.getToken(GoogleAccountActivity.this, email, AMEnv.GDRIVE_SCOPE);
onAuthenticated(token);
} catch (IOException e) {
activityComponents().errorUtil().showFatalError("IO Error", e);
} catch (UserRecoverableAuthException e) {
startActivityForResult(e.getIntent(), RC_AUTH_TOKEN);
} catch (GoogleAuthException e) {
activityComponents().errorUtil().showFatalError("GoogleAuthException", e);
}
}
});
} else if (requestCode == RC_AUTH_TOKEN) {
Bundle extra = data.getExtras();
if (extra == null) {
activityComponents().errorUtil().showFatalError("RC_AUTH_TOKEN does not have extra", null);
return;
}
String token = extra.getString("authtoken");
if (Strings.isNullOrEmpty(token)) {
activityComponents().errorUtil().showFatalError("RC_AUTH_TOKEN does not have token", null);
return;
}
onAuthenticated(token);
}
}
Aggregations