List of usage examples for android.accounts OperationCanceledException getMessage
public String getMessage()
From source file:sg.macbuntu.android.pushcontacts.DeviceRegistrar.java
private static String getAuthToken(Context context, Account account) { String authToken = null;//ww w.j ava 2s .c om AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, false, null, null); Bundle bundle = future.getResult(); authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); // User will be asked for "App Engine" permission. if (authToken == null) { // No auth token - will need to ask permission from user. Intent intent = new Intent(ActivityUI.AUTH_PERMISSION_ACTION); intent.putExtra("AccountManagerBundle", bundle); context.sendBroadcast(intent); } } catch (OperationCanceledException e) { Log.w(TAG, e.getMessage()); } catch (AuthenticatorException e) { Log.w(TAG, e.getMessage()); } catch (IOException e) { Log.w(TAG, e.getMessage()); } return authToken; }
From source file:com.browsertophone.AppEngineClient.java
private String getAuthToken(Context context, Account account) { String authToken = null;// ww w . j a va2 s. co m AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, false, null, null); Bundle bundle = future.getResult(); authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); // User will be asked for "App Engine" permission. if (authToken == null) { // No auth token - will need to ask permission from user. Intent intent = new Intent(SetupActivity.AUTH_PERMISSION_ACTION); intent.putExtra("AccountManagerBundle", bundle); context.sendBroadcast(intent); } } catch (OperationCanceledException e) { Log.w(TAG, e.getMessage()); } catch (AuthenticatorException e) { Log.w(TAG, e.getMessage()); } catch (IOException e) { Log.w(TAG, e.getMessage()); } return authToken; }
From source file:com.google.android.apps.chrometophone.AppEngineClient.java
private String getAuthToken(Context context, Account account) throws PendingAuthException { String authToken = null;/*from w w w.ja v a 2 s .c om*/ AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, false, null, null); Bundle bundle = future.getResult(); authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); if (authToken == null) { throw new PendingAuthException(bundle); } } catch (OperationCanceledException e) { Log.w(TAG, e.getMessage()); } catch (AuthenticatorException e) { Log.w(TAG, e.getMessage()); } catch (IOException e) { Log.w(TAG, e.getMessage()); } return authToken; }
From source file:com.agiro.scanner.android.AppEngineClient.java
private String getAuthToken(Context context, Account account) { String authToken = null;//from w ww. j av a 2 s.c o m AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, false, null, null); Bundle bundle = future.getResult(); Account[] accs = accountManager.getAccounts(); Log.v(TAG, "Account size = " + accs.length); Log.v(TAG, "Listing accounts"); for (Account acc : accs) { Log.v(TAG, "Account: " + acc); } authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); // User will be asked for "App Engine" permission. if (authToken == null) { Log.e(TAG, "No authToken"); // No auth token - will need to ask permission from user. Intent intent = new Intent("com.google.ctp.AUTH_PERMISSION"); intent.putExtra("AccountManagerBundle", bundle); context.sendBroadcast(intent); } } catch (OperationCanceledException e) { Log.w(TAG, e.getMessage()); } catch (AuthenticatorException e) { Log.w(TAG, e.getMessage()); } catch (IOException e) { Log.w(TAG, e.getMessage()); } return authToken; }
From source file:com.notifry.android.remote.BackendClient.java
private String getAuthToken(Context context, Account account) throws PendingAuthException { String authToken = null;/*from w ww .j a v a2 s. co m*/ AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, "ah", false, null, null); Bundle bundle = future.getResult(); authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); // User will be asked for "App Engine" permission. if (authToken == null) { // No auth token - will need to ask permission from user. Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT); if (intent != null) { // User input required context.startActivity(intent); throw new PendingAuthException("Asking user for permission."); } } } catch (OperationCanceledException e) { Log.w(TAG, e.getMessage()); } catch (AuthenticatorException e) { Log.w(TAG, e.getMessage()); } catch (IOException e) { Log.w(TAG, e.getMessage()); } return authToken; }
From source file:com.newtifry.android.remote.BackendClient.java
private String getAuthToken(Context context, Account account) throws PendingAuthException { String authToken = null;/* ww w . jav a 2s. co m*/ AccountManager accountManager = AccountManager.get(context); try { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, "ah", false, null, null); Bundle bundle = future.getResult(); authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); // User will be asked for "App Engine" permission. if (authToken == null) { // No authorization token - will need to ask permission from user. Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT); if (intent != null) { // User input required context.startActivity(intent); throw new PendingAuthException("Asking user for permission."); } } } catch (OperationCanceledException e) { Log.d(TAG, e.getMessage()); } catch (AuthenticatorException e) { Log.d(TAG, e.getMessage()); } catch (IOException e) { Log.d(TAG, e.getMessage()); } return authToken; }
From source file:cl.chileagil.agileday2012.fragment.MainFragment.java
private void chooseAccount() { accountManager.getAccountManager().getAuthTokenByFeatures(GoogleAccountManager.ACCOUNT_TYPE, AUTH_TOKEN_TYPE, null, MainFragment.this, null, null, new AccountManagerCallback<Bundle>() { public void run(AccountManagerFuture<Bundle> future) { Bundle bundle;/*from www . j a v a 2 s . c o m*/ try { bundle = future.getResult(); setAccountName(bundle.getString(AccountManager.KEY_ACCOUNT_NAME)); setAuthToken(bundle.getString(AccountManager.KEY_AUTHTOKEN)); onAuthToken(); } catch (OperationCanceledException e) { // user canceled } catch (AuthenticatorException e) { Log.e(TAG, e.getMessage(), e); } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } } }, null); }
From source file:org.hfoss.posit.android.sync.Communicator.java
public static String getAuthKey(Context context) { AccountManager accountManager = AccountManager.get(context); // TODO: again just picking the first account here.. how are you // supposed to handle this? Account[] accounts = accountManager.getAccountsByType(SyncAdapter.ACCOUNT_TYPE); if (accounts.length == 0) return null; String authKey = null;/*from w w w .j a va 2 s . c om*/ try { authKey = accountManager.blockingGetAuthToken(accounts[0], SyncAdapter.AUTHTOKEN_TYPE, true /* notifyAuthFailure */); } catch (OperationCanceledException e) { Log.e(TAG, "getAuthKey(), cancelled during request: " + e.getMessage()); e.printStackTrace(); } catch (AuthenticatorException e) { Log.e(TAG, "getAuthKey(), authentication exception: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { Log.e(TAG, "getAuthKey() IOException" + e.getMessage()); e.printStackTrace(); } catch (IllegalStateException e) { Log.e(TAG, "getAuthKey() IllegalStateException" + e.getMessage()); e.printStackTrace(); } return authKey; }
From source file:org.klnusbaum.udj.network.EventCommService.java
private void leaveEvent(AccountManager am, Account account, boolean attemptReauth) { Log.d(TAG, "In leave event"); if (account == null) { //TODO handle error return;/* www . j a va2 s. co m*/ } long userId; String authToken; try { userId = Long.valueOf(am.getUserData(account, Constants.USER_ID_DATA)); //TODO handle if event id isn't provided authToken = am.blockingGetAuthToken(account, "", true); } catch (OperationCanceledException e) { Log.e(TAG, "Operation canceled exception in EventCommService"); return; } catch (AuthenticatorException e) { Log.e(TAG, "Authenticator exception in EventCommService"); return; } catch (IOException e) { Log.e(TAG, "IO exception in EventCommService"); return; } try { long eventId = Long.valueOf(am.getUserData(account, Constants.LAST_EVENT_ID_DATA)); if (eventId != Constants.NO_EVENT_ID) { ServerConnection.leaveEvent(eventId, Long.valueOf(userId), authToken); setNotInEvent(account); Intent leftEventIntent = new Intent(Constants.LEFT_EVENT_ACTION); sendBroadcast(leftEventIntent); } } catch (IOException e) { Log.e(TAG, "IO exception in EventCommService: " + e.getMessage()); } catch (AuthenticationException e) { if (attemptReauth) { Log.e(TAG, "Soft Authentication exception in EventCommService"); am.invalidateAuthToken(Constants.ACCOUNT_TYPE, authToken); leaveEvent(am, account, false); } else { Log.e(TAG, "HARD Authentication exception in EventCommService"); } } finally { //TODO potential this get's repeated because it's already called once //above. I'll deal with that fact later. setNotInEvent(account); } //TODO need to implement exponential back off when log out fails. // 1. This is just nice to the server // 2. If we don't log out, there could be problems on the next event joined }
From source file:org.klnusbaum.udj.network.PlayerCommService.java
private void joinPlayer(Intent intent, AccountManager am, Account account, boolean attemptReauth) { if (!Utils.isNetworkAvailable(this)) { doLoginFail(am, account, PlayerJoinError.NO_NETWORK_ERROR); return;/*from w ww.ja va 2 s . c o m*/ } String userId = am.getUserData(account, Constants.USER_ID_DATA); String playerId = intent.getStringExtra(Constants.PLAYER_ID_EXTRA); String ownerId = intent.getStringExtra(Constants.PLAYER_OWNER_ID_EXTRA); if (userId.equals(ownerId)) { setLoggedInToPlayer(intent, am, account, playerId); return; } String authToken; String password = ""; boolean hasPassword = false; //TODO hanle error if account isn't provided try { //TODO handle if player id isn't provided authToken = am.blockingGetAuthToken(account, "", true); if (intent.hasExtra(Constants.PLAYER_PASSWORD_EXTRA)) { Log.d(TAG, "password given for player"); hasPassword = true; password = intent.getStringExtra(Constants.PLAYER_PASSWORD_EXTRA); } else { Log.d(TAG, "No password given for player"); } } catch (OperationCanceledException e) { Log.e(TAG, "Operation canceled exception"); doLoginFail(am, account, PlayerJoinError.AUTHENTICATION_ERROR); return; } catch (AuthenticatorException e) { Log.e(TAG, "Authenticator exception"); doLoginFail(am, account, PlayerJoinError.AUTHENTICATION_ERROR); return; } catch (IOException e) { Log.e(TAG, "IO exception"); doLoginFail(am, account, PlayerJoinError.AUTHENTICATION_ERROR); return; } try { if (!hasPassword) { ServerConnection.joinPlayer(playerId, authToken); } else { ServerConnection.joinPlayer(playerId, password, authToken); } setLoggedInToPlayer(intent, am, account, playerId); } catch (IOException e) { Log.e(TAG, "IO exception when joining player"); Log.e(TAG, e.getMessage()); doLoginFail(am, account, PlayerJoinError.SERVER_ERROR); } catch (JSONException e) { Log.e(TAG, "JSON exception when joining player"); Log.e(TAG, e.getMessage()); doLoginFail(am, account, PlayerJoinError.SERVER_ERROR); } catch (AuthenticationException e) { handleLoginAuthException(intent, am, account, authToken, attemptReauth); } catch (PlayerInactiveException e) { Log.e(TAG, "Player inactive Exception when joining player"); doLoginFail(am, account, PlayerJoinError.PLAYER_INACTIVE_ERROR); } catch (ParseException e) { e.printStackTrace(); doLoginFail(am, account, PlayerJoinError.SERVER_ERROR); } catch (PlayerPasswordException e) { Log.e(TAG, "Player Password Exception"); e.printStackTrace(); doLoginFail(am, account, PlayerJoinError.PLAYER_PASSWORD_ERROR); } catch (PlayerFullException e) { Log.e(TAG, "Player Password Exception"); e.printStackTrace(); doLoginFail(am, account, PlayerJoinError.PLAYER_FULL_ERROR); } catch (BannedException e) { Log.e(TAG, "Player Password Exception"); e.printStackTrace(); doLoginFail(am, account, PlayerJoinError.BANNED_ERROR); } }