Android AccountManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android AccountManager class.

This code example shows how to use the following methods:get
        super(context, executor);
    } 
 
    @Override 
    public final ResultT call() throws Exception { 
        final AccountManager manager = AccountManager.get(activity);
        final Account account = AccountUtils.getAccount(manager, activity);
 
        accountScope.enterWith(account, manager);
        try { 
            contextScope.enter(getContext());
            try { 
                return run(account);
            } catch (IOException e) {
                // Retry task if authentication failure occurs and account is 
                // successfully updated 
                if (AccountUtils.isUnauthorized(e)
                        && AccountUtils.updateAccount(account, activity))
                    return run(account);
                else 

9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:get
     */ 
    protected abstract D getAccountFailureData(); 
 
    @Override 
    public final D loadInBackground() { 
        final AccountManager manager = AccountManager.get(activity);
        final Account account;
        try { 
            account = AccountUtils.getAccount(manager, activity);
        } catch (IOException e) {
            return getAccountFailureData(); 
        } catch (AccountsException e) {
            return getAccountFailureData(); 
        } 
 
        accountScope.enterWith(account, manager);
        try { 
            contextScope.enter(getContext());
            try { 
                return load(account);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:get
    public void testGet() { 
        AccountManager appAM = AccountManager.get(app);
        assertThat(appAM).isNotNull();
        assertSame(AccountManager.get(app), appAM);
 
        Activity a = new Activity();
        assertThat(AccountManager.get(a)).isNotNull();
        assertThat(AccountManager.get(a)).isNotSameAs(appAM);
    } 
 
    @Test 
    public void testGetAccounts() { 
        AccountManager am = AccountManager.get(app);
        assertThat(am.getAccounts()).isNotNull();
        assertThat(am.getAccounts().length).isEqualTo(0);
 
        Account a1 = new Account("name_a", "type_a");
        Robolectric.shadowOf(am).addAccount(a1);
        assertThat(am.getAccounts()).isNotNull();
        assertThat(am.getAccounts().length).isEqualTo(1);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getPassword
     * Get password 
     * 
     * @return password 
     */ 
    public String getPassword() {
        return manager.getPassword(account);
    } 
 
    /** 
     * Get auth token 
     * 
     * @return token 
     */ 
    public String getAuthToken() {
        @SuppressWarnings("deprecation") 
        AccountManagerFuture<Bundle> future = manager.getAuthToken(account,
                ACCOUNT_TYPE, false, null, null); 
 
        try { 
            Bundle result = future.getResult();
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:addAccount, putParcelable
        outState.putBoolean(KEY_ADD_CALLED, mAddAccountCalled);
        if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "saved");
    } 
 
    private void addAccount(String accountType) {
        Bundle addAccountOptions = new Bundle();
        mPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(), 0);
        addAccountOptions.putParcelable(KEY_CALLER_IDENTITY, mPendingIntent);
        AccountManager.get(this).addAccount(
                accountType,
                null, /* authTokenType */ 
                null, /* requiredFeatures */ 
                addAccountOptions,
                this,
                mCallback,
                null /* handler */); 
        mAddAccountCalled  = true;
    } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setUserData
  /** 
   * Write a complete set of unversioned Account data suitable for testing forward migration. 
   * @throws Exception 
   */ 
  public void populateAccountData(final AccountManager accountManager, final Account account) throws Exception {
    accountManager.setUserData(account, "account.guid", TEST_GUID);
    accountManager.setUserData(account, "account.clientName", TEST_CLIENT_NAME);
    accountManager.setUserData(account, "account.numClients", new Long(TEST_NUM_CLIENTS).toString());
  } 
 
  public void testMigrateGlobals0and1() throws Exception { 
    final SharedPreferences v0a = new MockSharedPreferences();
    final SharedPreferences v1a = new MockSharedPreferences();
    final SharedPreferences v0b = new MockSharedPreferences();
    final SharedPreferences v1b = new MockSharedPreferences();
 
    populateGlobalSharedPrefs(v0a);
 
    final int NUM_GLOBALS = 2;
    assertEquals(NUM_GLOBALS, v0a.getAll().size());

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAccountsByType
 
//Android 2.0 
class AndroidFunctionality05 extends AndroidFunctionality04 implements AndroidFunctionality { 
 
    private Account AccessOwnerInfo_getAccount(AccountManager accountManager) {
        Account[] accounts = accountManager.getAccountsByType("com.google");
        Account account;
        if (accounts.length > 0) {
            account = accounts[0];
        } else { 
            account = null;
        } 
        return account;
    } 
 
    public String AccessOwnerInfo_getEmail(Context context) {
        AccountManager accountManager = AccountManager.get(context);
        Account account = AccessOwnerInfo_getAccount(accountManager);
 
        if (account == null) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAccountsByType
This code example shows how to use the following methods:addAccountExplicitly
            // There are two cases here: 
            // 1) We are called with a username/password; this comes from the traditional email 
            //    app UI; we simply create the account and return the proper bundle 
            if (options != null && options.containsKey(OPTIONS_PASSWORD)
                    && options.containsKey(OPTIONS_USERNAME)) {
                final Account account = new Account(options.getString(OPTIONS_USERNAME),
                        TEST_ACCOUNT_TYPE);
                AccountManager.get(EasTestAuthenticatorService.this).addAccountExplicitly(
                            account, options.getString(OPTIONS_PASSWORD), null);
 
                Bundle b = new Bundle();
                b.putString(AccountManager.KEY_ACCOUNT_NAME, TEST_ACCOUNT_TYPE);
                return b;
            // 2) The other case is that we're creating a new account from an Account manager 
            //    activity.  In this case, we add an intent that will be used to gather the 
            //    account information... 
            } else { 
                Bundle b = new Bundle();
                Intent intent =
                    AccountSetupBasics.actionSetupExchangeIntent(EasTestAuthenticatorService.this);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:addAccount, getAccountsByType, getAuthToken
        Bundle options = loginOptions.asBundle();
 
        // No account found - let's add one - the AuthenticatorService add account method will start the login activity 
        if (acc == null) {
            Log.i("ClientManager:getRestClient", "No account of type " + accountType + " found");
            accountManager.addAccount(getAccountType(),
                    AccountManager.KEY_AUTHTOKEN, null /*required features*/, options,
                    activityContext, new AccMgrCallback(restClientCallback),
                    null /* handler */); 
 
        } 
        // Account found 
        else { 
            Log.i("ClientManager:getRestClient", "Found account of type " + accountType);
            accountManager.getAuthToken(acc, AccountManager.KEY_AUTHTOKEN,
                    options, activityContext, new AccMgrCallback(restClientCallback), null /* handler */);
 
        } 
    } 
 

7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android AccountManager Questions & Answers:

See Code Examples for Android AccountManager Methods: