@Override public GooglePlayServicesAvailabilityException getCause() { return (GooglePlayServicesAvailabilityException) super.getCause(); }
private static void requestAuth(Context context, UserRecoverableAuthIOException userRecoverableException) { LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context); Intent authIntent = userRecoverableException.getIntent(); Intent runReqAuthIntent = new Intent(MainActivity.REQUEST_AUTHORIZATION_INTENT); runReqAuthIntent.putExtra(MainActivity.REQUEST_AUTHORIZATION_INTENT_PARAM, authIntent); manager.sendBroadcast(runReqAuthIntent); Log.d(TAG, String.format("Sent broadcast %s", MainActivity.REQUEST_AUTHORIZATION_INTENT)); }
@Override public void intercept(HttpRequest request) throws IOException { try { token = getToken(); request.getHeaders().setAuthorization("Bearer " + token); } catch (GooglePlayServicesAvailabilityException e) { throw new GooglePlayServicesAvailabilityIOException(e); } catch (UserRecoverableAuthException e) { throw new UserRecoverableAuthIOException(e); } catch (GoogleAuthException e) { throw new GoogleAuthIOException(e); } }
} catch (UserRecoverableAuthIOException userRecoverableException) { Log.i(TAG, String.format("UserRecoverableAuthIOException: %s", userRecoverableException.getMessage())); requestAuth(context, userRecoverableException); } catch (IOException e) {
@Override protected Void doInBackground(Void... voids) { YouTube youtube = new YouTube.Builder(transport, jsonFactory, credential).setApplicationName(Constants.APP_NAME) .build(); try { youtube.videos().update("snippet", updateVideo).execute(); } catch (UserRecoverableAuthIOException e) { startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION); } catch (IOException e) { Log.e(TAG, e.getMessage()); } return null; }
/** * Returns the {@link Intent} that when supplied to * {@link Activity#startActivityForResult(Intent, int)} will allow user intervention. */ public final Intent getIntent() { return getCause().getIntent(); } }
} catch (UserRecoverableAuthIOException userRecoverableException) { startActivityForResult( userRecoverableException.getIntent(), REQUEST_AUTHORIZATION); } catch (IOException e) {