List of usage examples for android.accounts AccountManager KEY_ERROR_CODE
String KEY_ERROR_CODE
To view the source code for android.accounts AccountManager KEY_ERROR_CODE.
Click Source Link
From source file:org.klnusbaum.udj.auth.Authenticator.java
@Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) {// w w w. j av a2 s. c o m final AccountManager am = AccountManager.get(context); final String password = am.getPassword(account); if (password != null) { try { final ServerConnection.AuthResult authResult = ServerConnection.authenticate(account.name, password); if (!TextUtils.isEmpty(authResult.ticketHash)) { am.setUserData(account, Constants.USER_ID_DATA, authResult.userId); return bundleUpAuthToken(account, authResult.ticketHash); } } catch (AuthenticationException e) { //TODO actually do something with this exception } catch (IOException e) { //TODO actually do something with this exception } catch (JSONException e) { //TODO actually do something with this exception } catch (APIVersionException e) { final Intent intent = new Intent(context, NeedUpdateActivity.class); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); intent.putExtra(AccountManager.KEY_ERROR_CODE, Constants.AUTH_API_VERSION_ERROR); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; } } //Oh snap, they're username and password didn't work. O well, better have // them sort it out. final Intent intent = new Intent(context, AuthActivity.class); intent.putExtra(AuthActivity.PARAM_USERNAME, account.name); intent.putExtra(AuthActivity.PARAM_AUTHTOKEN_TYPE, authTokenType); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; }
From source file:com.ntsync.android.sync.client.NetworkUtilities.java
/** * // w ww .jav a 2 s . com * @param acm * @param account * * * @param Activity * if null show a notification when Login is needed otherwise * show the Login-Activity in the context of the provided * Activity. * * @return SessionId * @throws OperationCanceledException * @throws ServerException * @throws NetworkErrorException */ @SuppressWarnings("deprecation") public static String blockingGetAuthToken(AccountManager acm, Account account, Activity activity) throws OperationCanceledException, ServerException, NetworkErrorException { String authToken = null; try { Bundle result; if (activity == null) { // New is available from API 14 -> use deprecated API result = acm.getAuthToken(account, Constants.AUTHTOKEN_TYPE, true, null, null).getResult(); } else { result = acm.getAuthToken(account, Constants.AUTHTOKEN_TYPE, null, activity, null, null) .getResult(); } if (result != null) { if (result.containsKey(AccountManager.KEY_AUTHTOKEN)) { authToken = result.getString(AccountManager.KEY_AUTHTOKEN); } if (result.containsKey(AccountManager.KEY_ERROR_CODE)) { int errorCode = result.getInt(AccountManager.KEY_ERROR_CODE, -1); String msg = result.getString(AccountManager.KEY_ERROR_MESSAGE); if (errorCode == Constants.AUTH_ERRORCODE_SERVEREXCEPTION) { throw new ServerException(msg); } else { LogHelper.logE(TAG, "Authentification failed with unknown errorCode:" + errorCode + " Message:" + msg, null); } } } } catch (AuthenticatorException e) { LogHelper.logE(TAG, "Authentification failed.", e); // Should not happen -> report error ErrorHandler.reportException(e); } catch (IOException ex) { throw new NetworkErrorException(ex); } return authToken; }