com.google.android.gms.auth.UserRecoverableAuthException Java Examples
The following examples show how to use
com.google.android.gms.auth.UserRecoverableAuthException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuthTaskUrlShortener.java From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License | 7 votes |
private void handleAuthException(final Activity activity, final Exception e) { activity.runOnUiThread(new Runnable() { @Override public void run() { if (e instanceof GooglePlayServicesAvailabilityException) { // The Google Play services APK is old, disabled, or not present. // Show a dialog created by Google Play services that allows // the user to update the APK int statusCode = ((GooglePlayServicesAvailabilityException) e).getConnectionStatusCode(); Dialog dialog = GooglePlayServicesUtil.getErrorDialog( statusCode, activity, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_URL_SHORTNER); dialog.show(); } else if (e instanceof UserRecoverableAuthException) { // Unable to authenticate, such as when the user has not yet granted // the app access to the account, but the user can fix this. // Forward the user to an activity in Google Play services. Intent intent = ((UserRecoverableAuthException) e).getIntent(); activity.startActivityForResult( intent, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_URL_SHORTNER); } } }); }
Example #2
Source File: SyncHelper.java From narrate-android with Apache License 2.0 | 6 votes |
public static List<AbsSyncService> getSyncServices() { List<AbsSyncService> syncServices = new ArrayList<>(); if (Settings.getDropboxSyncEnabled()) syncServices.add(new DropboxSyncService()); if (Settings.getGoogleDriveSyncEnabled()) { try { DriveSyncService syncService = new DriveSyncService(); syncServices.add(syncService); } catch (UserRecoverableAuthException e) { e.printStackTrace(); Settings.setGoogleDriveSyncEnabled(false); Toast.makeText(GlobalApplication.getAppContext(), "Google Drive Error. Disabling Drive sync for now.", Toast.LENGTH_LONG).show(); } } return syncServices; }
Example #3
Source File: RNGoogleSigninModule.java From google-signin with MIT License | 6 votes |
private void handleException(RNGoogleSigninModule moduleInstance, Exception cause, WritableMap userProperties, @Nullable WritableMap settings) { boolean isRecoverable = cause instanceof UserRecoverableAuthException; if (isRecoverable) { boolean shouldRecover = settings != null && settings.hasKey(SHOULD_RECOVER) && settings.getBoolean(SHOULD_RECOVER); if (shouldRecover) { attemptRecovery(moduleInstance, cause, userProperties); } else { moduleInstance.promiseWrapper.reject(ERROR_USER_RECOVERABLE_AUTH, cause); } } else { moduleInstance.promiseWrapper.reject(MODULE_NAME, cause); } }
Example #4
Source File: MainActivity.java From SyncManagerAndroid-DemoGoogleTasks with MIT License | 6 votes |
/** * Gets an authentication token from Google and handles any * GoogleAuthException that may occur. */ protected String fetchToken() throws IOException { try { return GoogleAuthUtil.getToken(MainActivity.this, mEmailText, mScope); } catch (UserRecoverableAuthException userRecoverableException) { // GooglePlayServices.apk is either old, disabled, or not present // so we need to show the user some UI in the activity to recover. //mActivity.handleException(userRecoverableException); //Log.e(TAG, userRecoverableException.getMessage(), userRecoverableException); mException = userRecoverableException; } catch (GoogleAuthException fatalException) { // Some other type of unrecoverable exception has occurred. // Report and log the error as appropriate for your app. Log.e(TAG, fatalException.getMessage(), fatalException); } return null; }
Example #5
Source File: AuthorizedServiceTask.java From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void handleAuthException(final Activity activity, final Exception e) { activity.runOnUiThread(new Runnable() { @Override public void run() { if (e instanceof GooglePlayServicesAvailabilityException) { // The Google Play services APK is old, disabled, or not present. // Show a dialog created by Google Play services that allows // the user to update the APK int statusCode = ((GooglePlayServicesAvailabilityException) e).getConnectionStatusCode(); Dialog dialog; if(authScope.equals(AUTH_PROXIMITY_API)) { dialog = GooglePlayServicesUtil.getErrorDialog( statusCode, activity, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_PRX_API); } else { dialog = GooglePlayServicesUtil.getErrorDialog( statusCode, activity, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_URL_SHORTNER); } dialog.show(); } else if (e instanceof UserRecoverableAuthException) { // Unable to authenticate, such as when the user has not yet granted // the app access to the account, but the user can fix this. // Forward the user to an activity in Google Play services. Intent intent = ((UserRecoverableAuthException) e).getIntent(); if(authScope.equals(AUTH_PROXIMITY_API)) { activity.startActivityForResult( intent, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_PRX_API); } else { activity.startActivityForResult( intent, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_URL_SHORTNER); } } } }); }
Example #6
Source File: DriveSyncService.java From narrate-android with Apache License 2.0 | 5 votes |
public DriveSyncService() throws UserRecoverableAuthException { super(SyncService.GoogleDrive); try { HttpTransport httpTransport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); String token = GoogleAuthUtil.getToken(GlobalApplication.getAppContext(), Settings.getEmail(), "oauth2:" + DriveScopes.DRIVE_APPDATA); if (SettingsUtil.shouldRefreshGDriveToken()) { GoogleAuthUtil.clearToken(GlobalApplication.getAppContext(), token); token = GoogleAuthUtil.getToken(GlobalApplication.getAppContext(), Settings.getEmail(), "oauth2:" + DriveScopes.DRIVE_APPDATA); SettingsUtil.refreshGDriveToken(); } if (BuildConfig.DEBUG) LogUtil.log(getClass().getSimpleName(), "Access Token: " + token); GoogleCredential credential = new GoogleCredential().setAccessToken(token); service = new Drive.Builder(httpTransport, jsonFactory, credential).setApplicationName("Narrate").build(); } catch (UserRecoverableAuthException ue) { throw ue; } catch (Exception e) { LogUtil.log(getClass().getSimpleName(), "Exception in creation: " + e); if (!BuildConfig.DEBUG) Crashlytics.logException(e); } if (CLEAR_FOLDER_CONTENTS) { deleteEverything(); } }
Example #7
Source File: RNGoogleSigninModule.java From google-signin with MIT License | 5 votes |
private void attemptRecovery(RNGoogleSigninModule moduleInstance, Exception e, WritableMap userProperties) { Activity activity = moduleInstance.getCurrentActivity(); if (activity == null) { moduleInstance.pendingAuthRecovery = null; moduleInstance.promiseWrapper.reject(MODULE_NAME, "Cannot attempt recovery auth because app is not in foreground. " + e.getLocalizedMessage()); } else { moduleInstance.pendingAuthRecovery = new PendingAuthRecovery(userProperties); Intent recoveryIntent = ((UserRecoverableAuthException) e).getIntent(); activity.startActivityForResult(recoveryIntent, REQUEST_CODE_RECOVER_AUTH); } }
Example #8
Source File: SignInPresenter.java From ribot-app-android with Apache License 2.0 | 5 votes |
public void signInWithGoogle(final Account account) { Timber.i("Starting sign in with account " + account.name); mMvpView.showProgress(true); mMvpView.setSignInButtonEnabled(false); mSubscription = mDataManager.signIn(account) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(new Subscriber<Ribot>() { @Override public void onCompleted() { mMvpView.showProgress(false); } @Override public void onError(Throwable e) { mMvpView.showProgress(false); Timber.w("Sign in has called onError" + e); if (e instanceof UserRecoverableAuthException) { Timber.w("UserRecoverableAuthException has happen"); Intent recover = ((UserRecoverableAuthException) e).getIntent(); mMvpView.onUserRecoverableAuthException(recover); } else { mMvpView.setSignInButtonEnabled(true); if (NetworkUtil.isHttpStatusCode(e, 403)) { // Google Auth was successful, but the user does not have a ribot // profile set up. mMvpView.showProfileNotFoundError(account.name); } else { mMvpView.showGeneralSignInError(); } } } @Override public void onNext(Ribot ribot) { Timber.i("Sign in successful. Profile name: " + ribot.profile.name.first); mMvpView.onSignInSuccessful(ribot.profile); } }); }
Example #9
Source File: SignInPresenterTest.java From ribot-app-android with Apache License 2.0 | 5 votes |
@Test public void signInFailedWithUserRecoverableException() { //Stub mock data manager Intent intent = new Intent(); UserRecoverableAuthException exception = new UserRecoverableAuthException("error", intent); stubDataManagerSignIn(Observable.error(exception)); mSignInPresenter.signInWithGoogle(mAccount); //Check that the right methods are called verify(mMockSignInMvpView).showProgress(true); verify(mMockSignInMvpView).onUserRecoverableAuthException(any(Intent.class)); verify(mMockSignInMvpView).showProgress(false); verify(mMockSignInMvpView).setSignInButtonEnabled(false); }
Example #10
Source File: GoogleOauth2.java From edx-app-android with Apache License 2.0 | 5 votes |
/** * Gets an authentication token from Google and handles any * GoogleAuthException that may occur. */ protected String fetchToken() throws IOException { if ( activity == null ) return null; try { logger.debug("Fetching google oauth2 token ..."); return GoogleAuthUtil.getToken(activity, mEmail, mScope); } catch (UserRecoverableAuthException userRecoverableException) { // GooglePlayServices.apk is either old, disabled, or not present // so we need to show the user some UI in the activity to recover. logger.debug("User recoverable error occurred"); logger.error(userRecoverableException); // Requesting an authorization code will always throw // UserRecoverableAuthException on the first call to GoogleAuthUtil.getToken // because the user must consent to offline access to their data. After // consent is granted control is returned to your activity in onActivityResult // and the second call to GoogleAuthUtil.getToken will succeed. if (activity != null && userRecoverableException.getIntent() != null) { activity.startActivityForResult(userRecoverableException.getIntent(), REQUEST_AUTHORIZATION); } } catch (GoogleAuthException fatalException) { logger.warn("google auth error occurred"); // Some other type of unrecoverable exception has occurred. // Report and log the error as appropriate for your app. logger.error(fatalException); } return null; }
Example #11
Source File: MainActivity.java From SyncManagerAndroid-DemoGoogleTasks with MIT License | 5 votes |
protected void handleException(UserRecoverableAuthException e) { // Unable to authenticate, such as when the user has not yet granted // the app access to the account, but the user can fix this. // Forward the user to an activity in Google Play services. Intent intent = e.getIntent(); startActivityForResult(intent, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR); }
Example #12
Source File: UserRecoverableAuthIOException.java From google-api-java-client with Apache License 2.0 | 4 votes |
/** * @since 1.21.0 */ public UserRecoverableAuthIOException(UserRecoverableAuthException wrapped) { super(wrapped); }
Example #13
Source File: UserRecoverableAuthIOException.java From google-api-java-client with Apache License 2.0 | 4 votes |
@Override public UserRecoverableAuthException getCause() { return (UserRecoverableAuthException) super.getCause(); }