List of usage examples for android.accounts AccountManager get
public static AccountManager get(Context context)
From source file:com.android.browser.GoogleAccountLogin.java
@Override public void run(AccountManagerFuture<Bundle> value) { try {//from www . j a v a2 s. c om String id = value.getResult().getString(AccountManager.KEY_AUTHTOKEN); switch (mState) { default: case 0: throw new IllegalStateException("Impossible to get into this state"); case 1: mSid = id; mState = 2; // LSID AccountManager.get(mActivity).getAuthToken(mAccount, "LSID", null, mActivity, this, null); break; case 2: mLsid = id; new Thread(this).start(); break; } } catch (Exception e) { Log.d(LOGTAG, "LOGIN_FAIL: Exception in state " + mState + " " + e); // For all exceptions load the original signin page. // TODO: toast login failed? done(); } }
From source file:dev.drsoran.moloko.sync.SyncAdapter.java
private void invalidateAccount(String authToken) { final AccountManager accountManager = AccountManager.get(context); accountManager.invalidateAuthToken(Constants.ACCOUNT_TYPE, authToken); }
From source file:edu.mit.mobile.android.locast.accounts.Authenticator.java
public static String getUserData(Context context, String key) { final Account account = getFirstAccount(context); if (account == null) { throw new RuntimeException("no accounts registered"); }/*from ww w .j a va 2 s .c o m*/ return AccountManager.get(context).getUserData(account, key); }
From source file:com.newtifry.android.remote.BackendClient.java
private String getAuthToken(Context context, Account account) throws PendingAuthException { String authToken = null;//from w w w. j av a 2s .c om 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:ir.keloud.android.lib.common.accounts.AccountUtils.java
public static void saveClient(KeloudClient client, Account savedAccount, Context context) { // Account Manager AccountManager ac = AccountManager.get(context.getApplicationContext()); if (client != null) { String cookiesString = client.getCookiesString(); if (cookiesString != "") { ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString); // Log_OC.d(TAG, "Saving Cookies: "+ cookiesString ); }// w w w . ja v a2 s. com } }
From source file:de.unclenet.dehabewe.CalendarActivity.java
private void gotAccount(boolean tokenExpired) { SharedPreferences settings = getSharedPreferences(PREF, 0); String accountName = settings.getString("accountName", null); if (accountName != null) { AccountManager manager = AccountManager.get(this); Account[] accounts = manager.getAccountsByType("com.google"); int size = accounts.length; for (int i = 0; i < size; i++) { Account account = accounts[i]; if (accountName.equals(account.name)) { if (tokenExpired) { manager.invalidateAuthToken("com.google", this.authToken); }/* ww w. j ava 2 s. c om*/ gotAccount(manager, account); return; } } } showDialog(DIALOG_ACCOUNTS); }
From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java
@Override public void invalidateToken(Context context, String inAuthority) { // final String authority = inAuthority == null ? Constants.AUTHORITY_DEFAULT : inAuthority; AccountManager am = AccountManager.get(context); am.invalidateAuthToken(Constants.getAccountType(context), readToken(context, inAuthority)); // am.removeAccount(new Account(Constants.getAccountName(context), Constants.getAccountType(context)), null, null); }
From source file:com.owncloud.android.ui.activity.ManageAccountsActivity.java
/** * creates the account list items list including the add-account action in case multiaccount_support is enabled. * * @return list of account list items/*from w w w . j a va2 s . co m*/ */ private ArrayList<AccountListItem> getAccountListItems() { Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType()); ArrayList<AccountListItem> adapterAccountList = new ArrayList<AccountListItem>(accountList.length); for (Account account : accountList) { adapterAccountList.add(new AccountListItem(account)); } // Add Create Account item at the end of account list if multi-account is enabled if (getResources().getBoolean(R.bool.multiaccount_support)) { adapterAccountList.add(new AccountListItem()); } return adapterAccountList; }
From source file:com.owncloud.android.lib.common.accounts.AccountUtils.java
public static void saveClient(OwnCloudClient client, Account savedAccount, Context context) { // Account Manager AccountManager ac = AccountManager.get(context.getApplicationContext()); if (client != null) { String cookiesString = client.getCookiesString(); if (cookiesString != "") { ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString); // Log_OC.d(TAG, "Saving Cookies: "+ cookiesString ); }/* www . ja va2s .co m*/ } }
From source file:git.egatuts.nxtremotecontroller.fragment.OnlineControllerFragment.java
public String getOwnerEmail() { AccountManager manager = AccountManager.get(this.getActivity()); Account[] accounts = manager.getAccountsByType("com.google"); return accounts[0].name; }