List of usage examples for android.accounts AccountManager get
public static AccountManager get(Context context)
From source file:com.android.calendar.selectcalendars.SelectSyncedCalendarsMultiAccountAdapter.java
public SelectSyncedCalendarsMultiAccountAdapter(Context context, Cursor acctsCursor, SelectSyncedCalendarsMultiAccountActivity act) { super(acctsCursor, context); mSyncedText = context.getString(R.string.synced); mNotSyncedText = context.getString(R.string.not_synced); mCache = new CalendarColorCache(context, this); mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mResolver = context.getContentResolver(); mActivity = act;/* ww w . j a v a 2 s. c o m*/ mFragmentManager = act.getSupportFragmentManager(); mColorPickerDialog = (CalendarColorPickerDialog) mFragmentManager .findFragmentByTag(COLOR_PICKER_DIALOG_TAG); mIsTablet = Utils.getConfigBool(context, R.bool.tablet_config); if (mCalendarsUpdater == null) { mCalendarsUpdater = new AsyncCalendarsUpdater(mResolver); } if (acctsCursor == null || acctsCursor.getCount() == 0) { Log.i(TAG, "SelectCalendarsAdapter: No accounts were returned!"); } // Collect proper description for account types mAuthDescs = AccountManager.get(context).getAuthenticatorTypes(); for (int i = 0; i < mAuthDescs.length; i++) { mTypeToAuthDescription.put(mAuthDescs[i].type, mAuthDescs[i]); } mView = mActivity.getExpandableListView(); mRefresh = true; mClosedCursorsFlag = false; mColorViewTouchAreaIncrease = context.getResources() .getDimensionPixelSize(R.dimen.color_view_touch_area_increase); }
From source file:au.com.domain.AccountsAutoCompleteTextView.java
private List<String> getGoogleAccountEmails(Context context) { List<String> emails = new ArrayList<>(); if (isPermissionGranted()) { //noinspection MissingPermission isPermission() is doing the check required by lint Account[] accounts = AccountManager.get(context).getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE); for (Account account : accounts) { if (android.util.Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) { emails.add(account.name); }/*from www. ja v a 2 s. c om*/ } Collections.sort(emails, String.CASE_INSENSITIVE_ORDER); } return emails; }
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/* ww w. j a va2 s. co 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.he5ed.lib.cloudprovider.apis.BoxApi.java
@Override public synchronized void prepareApi(OnPrepareListener prepareListener) { mPrepareListener = prepareListener;/* w w w . j a v a2s . c o m*/ AccountManager.get(mContext).getAuthToken(mAccount, CloudProvider.AUTH_TYPE, false, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { mAccessToken = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); validateAccessToken(); } catch (OperationCanceledException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); if (mPrepareListener != null) mPrepareListener.onPrepareFail(e); } catch (IOException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); if (mPrepareListener != null) mPrepareListener.onPrepareFail(e); } catch (AuthenticatorException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); if (mPrepareListener != null) mPrepareListener.onPrepareFail(e); } } }, null); }
From source file:com.hemou.android.account.AccountUtils.java
/** * Update account//ww w .j a v a 2 s . c o m * * @param account * @param act * @return true if account was updated, false otherwise */ public static boolean updateAccount(final Account account, final Activity act) { if (act == null) throw new IllegalArgumentException("Activity cannot be null"); final String SUB_TAG = "acnt_update"; int count = UPDATE_COUNT.get(); synchronized (UPDATE_COUNT) { // Don't update the account if the account was successfully updated // while the lock was being waited for if (count != UPDATE_COUNT.get()) return true; AccountManager manager = AccountManager.get(act); try { if (!hasAuthenticator(manager)) throw new AuthenticatorConflictException(); manager.updateCredentials(account, AUTHTOKEN_TYPE, null, act, null, null).getResult(); UPDATE_COUNT.incrementAndGet(); return true; } catch (OperationCanceledException e) { Log.d(SUB_TAG, "Excepting retrieving account", e); act.finish(); return false; } catch (AccountsException e) { Log.d(SUB_TAG, "Excepting retrieving account", e); return false; } catch (AuthenticatorConflictException e) { act.runOnUiThread(new Runnable() { public void run() { showConflictMessage(act); } }); return false; } catch (IOException e) { Log.d(SUB_TAG, "Excepting retrieving account", e); return false; } } }
From source file:com.cerema.cloud2.lib.common.accounts.AccountUtils.java
/** * Restore the client cookies from accountName * @param accountName//from w w w . j a v a2s . c o m * @param client * @param context */ public static void restoreCookies(String accountName, OwnCloudClient client, Context context) { Log_OC.d(TAG, "Restoring cookies for " + accountName); // Account Manager AccountManager am = AccountManager.get(context.getApplicationContext()); // Get account Account account = null; Account accounts[] = am.getAccounts(); for (Account a : accounts) { if (a.name.equals(accountName)) { account = a; break; } } // Restoring cookies if (account != null) { restoreCookies(account, client, context); } }
From source file:org.klnusbaum.udj.network.EventCommService.java
private void setNotInEvent(Account account) { AccountManager am = AccountManager.get(this); am.setUserData(account, Constants.LAST_EVENT_ID_DATA, String.valueOf(Constants.NO_EVENT_ID)); am.setUserData(account, Constants.EVENT_STATE_DATA, String.valueOf(Constants.NOT_IN_EVENT)); }
From source file:com.google.ipc.invalidation.ticl.android.AndroidChannel.java
/** * Initiates acquisition of an authentication token that can be used with channel HTTP requests. * Android token acquisition is asynchronous since it may require HTTP interactions with the * ClientLogin servers to obtain the token. *///from w w w .ja v a 2s . co m @SuppressWarnings("deprecation") synchronized void requestAuthToken(final CompletionCallback callback) { // If there is currently no token and no pending request, initiate one. if (disableAccountManager) { logger.fine("Not requesting auth token since account manager disabled"); return; } if (authToken == null) { // Ask the AccountManager for the token, with a pending future to store it on the channel // once available. final AndroidChannel theChannel = this; AccountManager accountManager = AccountManager.get(proxy.getService()); accountManager.getAuthToken(proxy.getAccount(), proxy.getAuthType(), true, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle result = future.getResult(); if (result.containsKey(AccountManager.KEY_INTENT)) { // TODO: Handle case where there are no authentication // credentials associated with the client account logger.severe("Token acquisition requires user login"); callback.success(); // No further retries. } setAuthToken(result.getString(AccountManager.KEY_AUTHTOKEN)); } catch (OperationCanceledException exception) { logger.warning("Auth cancelled", exception); // TODO: Send error to client } catch (AuthenticatorException exception) { logger.warning("Auth error acquiring token", exception); callback.failure(); } catch (IOException exception) { logger.warning("IO Exception acquiring token", exception); callback.failure(); } } }, null); } else { logger.fine("Auth token request already pending"); callback.success(); } }
From source file:com.he5ed.lib.cloudprovider.apis.CloudDriveApi.java
@Override public synchronized void prepareApi(BaseApi.OnPrepareListener prepareListener) { mPrepareListener = prepareListener;//w w w.ja va2 s . co m AccountManager.get(mContext).getAuthToken(mAccount, CloudProvider.AUTH_TYPE, false, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { mAccessToken = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); validateAccessToken(); } catch (OperationCanceledException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); if (mPrepareListener != null) mPrepareListener.onPrepareFail(e); } catch (IOException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); if (mPrepareListener != null) mPrepareListener.onPrepareFail(e); } catch (AuthenticatorException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); if (mPrepareListener != null) mPrepareListener.onPrepareFail(e); } } }, null); }
From source file:com.quarterfull.newsAndroid.NewsReaderListActivity.java
/** * Check if the account is in the Android Account Manager. If not it will be added automatically *///from w w w . ja va 2 s. c o m private void initAccountManager() { AccountManager mAccountManager = AccountManager.get(this); boolean isAccountThere = false; Account[] accounts = mAccountManager.getAccounts(); for (Account account : accounts) { if (account.type.intern().equals(AccountGeneral.ACCOUNT_TYPE)) { isAccountThere = true; } } //If the account is not in the Android Account Manager if (!isAccountThere) { //Then add the new account Account account = new Account(getString(R.string.app_name), AccountGeneral.ACCOUNT_TYPE); mAccountManager.addAccountExplicitly(account, "", new Bundle()); SyncIntervalSelectorActivity.SetAccountSyncInterval(this); } }