List of usage examples for android.accounts AccountManagerFuture getResult
V getResult() throws OperationCanceledException, IOException, AuthenticatorException;
From source file:org.mozilla.gecko.sync.syncadapter.SyncAdapter.java
private void invalidateAuthToken(Account account) { AccountManagerFuture<Bundle> future = getAuthToken(account, null, null); String token;// ww w . ja v a 2s . c o m try { token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); mAccountManager.invalidateAuthToken(Constants.ACCOUNTTYPE_SYNC, token); } catch (Exception e) { Log.e(LOG_TAG, "Couldn't invalidate auth token: " + e); } }
From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java
@Override public String getAuthToken(Context ctx, String inAuthority) throws OperationCanceledException, AuthenticatorException, IOException { final String authority = inAuthority == null ? Constants.AUTHORITY_DEFAULT : inAuthority; AccountManager am = AccountManager.get(ctx); AccountManagerFuture<Bundle> future = am.getAuthToken( new Account(Constants.getAccountName(ctx), Constants.getAccountType(ctx)), authority, true, null, null);// w w w . j a v a 2s. c o m String token = null; if (future.isDone()) { token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); } return token; }
From source file:com.mobilyzer.AccountSelector.java
private void getAuthToken(AccountManagerFuture<Bundle> result) { Logger.i("getAuthToken() called, result " + result); String errMsg = "Failed to get login cookie. "; Bundle bundle;// w w w . ja v a 2 s. com try { bundle = result.getResult(); Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT); if (intent != null) { // User input required. (A UI will pop up for user's consent to allow // this app access account information.) Logger.i("Starting account manager activity"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); } else { Logger.i("Executing getCookie task"); synchronized (this) { this.authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); this.checkinFuture = checkinExecutor.submit(new GetCookieTask()); } } } catch (OperationCanceledException e) { Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } catch (AuthenticatorException e) { Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } catch (IOException e) { Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } }
From source file:com.google.android.apps.mytracks.AbstractSendToGoogleActivity.java
private void onDrivePermissionSuccess() { // Check Maps permission if (sendRequest.isSendMaps()) { AccountManager.get(this).getAuthToken(sendRequest.getAccount(), MapsConstants.SERVICE_NAME, null, this, new AccountManagerCallback<Bundle>() { @Override//from w ww. ja v a2s. c o m public void run(AccountManagerFuture<Bundle> future) { try { if (future.getResult().getString(AccountManager.KEY_AUTHTOKEN) != null) { runOnUiThread(new Runnable() { @Override public void run() { onMapsPermissionSuccess(); } }); return; } else { Log.d(TAG, "auth token is null"); } } catch (OperationCanceledException e) { Log.d(TAG, "Unable to get auth token", e); } catch (AuthenticatorException e) { Log.d(TAG, "Unable to get auth token", e); } catch (IOException e) { Log.d(TAG, "Unable to get auth token", e); } runOnUiThread(new Runnable() { @Override public void run() { onPermissionFailure(); } }); } }, null); } else { onMapsPermissionSuccess(); } }
From source file:com.owncloud.android.ui.activity.ManageAccountsActivity.java
@Override public void createAccount() { AccountManager am = AccountManager.get(getApplicationContext()); am.addAccount(MainApp.getAccountType(), null, null, null, this, new AccountManagerCallback<Bundle>() { @Override/*from w w w. j a v a 2 s . c o m*/ public void run(AccountManagerFuture<Bundle> future) { if (future != null) { try { Bundle result = future.getResult(); String name = result.getString(AccountManager.KEY_ACCOUNT_NAME); AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), name); mAccountListAdapter = new AccountListAdapter(ManageAccountsActivity.this, getAccountListItems(), mTintedCheck); mListView.setAdapter(mAccountListAdapter); runOnUiThread(new Runnable() { @Override public void run() { mAccountListAdapter.notifyDataSetChanged(); } }); } catch (OperationCanceledException e) { Log_OC.d(TAG, "Account creation canceled"); } catch (Exception e) { Log_OC.e(TAG, "Account creation finished in exception: ", e); } } } }, mHandler); }
From source file:be.evias.cloudLogin.cloudLoginRunPointActivity.java
/** * Get the auth token for an existing account on the AccountManager. * * @param account Account//from w ww . j a v a 2s . c o m * @param authTokenType String */ private void getAccountAuthToken(final Account account, String authTokenType) { final AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(account, authTokenType, null, this, null, null); new Thread(new Runnable() { @Override public void run() { try { Bundle bnd = future.getResult(); final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN); Log.d("cloudLogin", "cloudLoginRunPointActivity/getAccountAuthToken: User still logged in. Bundle: " + bnd); SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean("cloudlogin_active_account", true); editor.putString("cloudlogin_active_account_name", account.name); editor.commit(); displayNavigationDrawer(bnd, account); } catch (Exception e) { e.printStackTrace(); showMessage(e.getMessage(), Toast.LENGTH_LONG); SharedPreferences.Editor editor = mPrefs.edit(); editor.putBoolean("cloudlogin_active_account", false); editor.commit(); } } }).start(); }
From source file:mobisocial.musubi.ui.fragments.AccountLinkDialog.java
private static String blockForCachedGoogleToken(Context context, Account account, AccountManager accountManager) throws IOException { AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, GOOGLE_OAUTH_SCOPE, true, null, null);//from w w w . j ava 2 s . c om if (future != null) { try { Bundle result = future.getResult(); if (result.containsKey(AccountManager.KEY_AUTHTOKEN)) { String cachedGoogleToken = result.getString(AccountManager.KEY_AUTHTOKEN); return cachedGoogleToken; } } catch (IOException e) { throw e; } catch (Exception e) { } } return null; }
From source file:org.amahi.anywhere.fragment.NavigationFragment.java
@Override public void run(AccountManagerFuture<Bundle> accountManagerFuture) { try {/*from ww w .j a va 2 s . c o m*/ Bundle accountManagerResult = accountManagerFuture.getResult(); String authenticationToken = accountManagerResult.getString(AccountManager.KEY_AUTHTOKEN); if (authenticationToken != null) { setUpServers(authenticationToken); } else { setUpAuthenticationToken(); } } catch (OperationCanceledException e) { tearDownActivity(); } catch (IOException | AuthenticatorException e) { throw new RuntimeException(e); } }
From source file:cl.chileagil.agileday2012.fragment.MainFragment.java
void gotAccount() { Account account = accountManager.getAccountByName(accountName); if (account == null) { chooseAccount();/*from w ww. jav a 2s .c o m*/ return; } if (authToken != null) { //Ya tengo elegido mi cuenta. //Solo si no tengo datos en la DB, lo pido, sino cargo lo que hay //y actualizo solo a peticion del usuario DatabaseAdapter dbAdapter = null; try { dbAdapter = new DatabaseAdapter(this); dbAdapter.open(); if (dbAdapter.fetchCountEvents() <= 0) { onAuthToken(); } } catch (Exception e) { e.printStackTrace(); } finally { try { dbAdapter.close(); } catch (Exception e) { e.printStackTrace(); } } return; } accountManager.getAccountManager().getAuthToken(account, AUTH_TOKEN_TYPE, true, new AccountManagerCallback<Bundle>() { public void run(AccountManagerFuture<Bundle> future) { try { Bundle bundle = future.getResult(); if (bundle.containsKey(AccountManager.KEY_INTENT)) { Intent intent = bundle.getParcelable(AccountManager.KEY_INTENT); intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_TASK); startActivityForResult(intent, REQUEST_AUTHENTICATE); } else if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) { setAuthToken(bundle.getString(AccountManager.KEY_AUTHTOKEN)); onAuthToken(); } } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } } }, null); }
From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java
@Override public String getAuthToken(Context ctx, String inAuthority, IntentSender intentSender) throws OperationCanceledException, AuthenticatorException, IOException { final String authority = inAuthority == null ? Constants.AUTHORITY_DEFAULT : inAuthority; AccountManager am = AccountManager.get(ctx); AccountManagerFuture<Bundle> future = am.getAuthToken( new Account(Constants.getAccountName(ctx), Constants.getAccountType(ctx)), authority, false, new OnTokenAcquired(ctx, authority, intentSender), null); String token = null;/* w w w . j a v a 2 s . com*/ if (future.isDone()) { token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); } return token; }