Android Account - 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 Account class.

This code example shows how to use the following methods:
        Robolectric.shadowOf(am).addAccount(a1);
        assertThat(am.getAccounts()).isNotNull();
        assertThat(am.getAccounts().length).isEqualTo(1);
        assertThat(am.getAccounts()[0]).isSameAs(a1);
 
        Account a2 = new Account("name_b", "type_b");
        Robolectric.shadowOf(am).addAccount(a2);
        assertThat(am.getAccounts()).isNotNull();
        assertThat(am.getAccounts().length).isEqualTo(2);
        assertThat(am.getAccounts()[1]).isSameAs(a2);
    } 
 
    @Test 
    public void testGetAccountsByType() { 
        AccountManager am = AccountManager.get(app);
        assertThat(am.getAccountsByType("name_a")).isNotNull();
        assertThat(am.getAccounts().length).isEqualTo(0);
 
        Account a1 = new Account("name_a", "type_a");
        Robolectric.shadowOf(am).addAccount(a1);
8
CodeRank
This code example shows how to use the following methods:
    } 
 
    @LargeTest 
    public void testAuthorityPersistence() throws Exception { 
        final Account account1 = new Account("a@example.com", "example.type");
        final Account account2 = new Account("b@example.com", "example.type.2");
        final String authority1 = "testprovider1";
        final String authority2 = "testprovider2";
        final Bundle extras1 = new Bundle();
        extras1.putString("a", "1");
        final Bundle extras2 = new Bundle();
        extras2.putString("a", "2");
        extras2.putLong("b", 2);
        extras2.putInt("c", 1);
        extras2.putBoolean("d", true);
        extras2.putDouble("e", 1.2);
        extras2.putFloat("f", 4.5f);
        extras2.putParcelable("g", account1);
        final int period1 = 200;
        final int period2 = 1000;

8
CodeRank
This code example shows how to use the following methods:
 
    /** 
     * Test sorting of users that match login 
     */ 
    public void testLoginMatch() { 
        GitHubAccount account = new GitHubAccount(new Account("m", "t"),
                AccountManager.get(getContext()));
        UserComparator comparator = new UserComparator(account);
 
        assertTrue(comparator.compare(new User().setLogin("m"),
                new User().setLogin("a")) < 0); 
        assertTrue(comparator.compare(new User().setLogin("a"),
                new User().setLogin("m")) > 0); 
        assertTrue(comparator.compare(new User().setLogin("m"),
                new User().setLogin("z")) < 0); 
        assertTrue(comparator.compare(new User().setLogin("z"),
                new User().setLogin("m")) > 0); 
        assertEquals(
                0, 
                comparator.compare(new User().setLogin("m"),
8
CodeRank
This code example shows how to use the following methods:toString
        new Account("name", "");
    } 
 
    @Test 
    public void shouldHaveToString() throws Exception { 
        Account account = new Account("name", "type");
        assertThat(account.toString()).isEqualTo("Account {name=name, type=type}");
    } 
 
    @Test 
    public void shouldProvideEqualAndHashCode() throws Exception { 
        assertThat(new Account("a", "b")).isEqualTo(new Account("a", "b"));
        assertThat(new Account("a", "b")).isNotEqualTo(new Account("c", "b"));
        assertThat(new Account("a", "b").hashCode()).isEqualTo(new Account("a", "b").hashCode());
        assertThat(new Account("a", "b").hashCode()).isNotEqualTo(new Account("c", "b").hashCode());
    } 
} 
7
CodeRank
This code example shows how to use the following methods:
@RunWith(TestRunners.WithDefaults.class) 
public class PeriodicSyncTest { 
 
    @Test 
    public void shouldHaveConstructor() throws Exception { 
        Account a = new Account("a", "b"); 
        PeriodicSync sync = new PeriodicSync(a, "auth", 
                new Bundle(), 120l); 
 
        assertThat(sync.account).isSameAs(a); 
        assertThat(sync.authority).isEqualTo("auth"); 
        assertThat(sync.period).isEqualTo(120l); 
        assertNotNull(sync.extras); 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:
    public void testForwardingToLocalInvisibleContacts() { 
 
        // Visible because there is no account 
        long contactId1 = queryContactId(createRawContactWithName("Bob", "Parr"));
 
        Account account = new Account("accountName", "accountType");
        long groupId = createGroup(account, "sid", "def",
                0 /* visible */,  true /* auto-add */, false /* fav */); 
        long contactId2 = queryContactId(createRawContactWithName("Helen", "Parr",
                account));
 
        Uri contentUri = Contacts.CONTENT_URI.buildUpon().appendQueryParameter(
                ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(Directory.LOCAL_INVISIBLE))
                .build();
 
        Cursor cursor = mResolver.query(contentUri,
                new String[]{Contacts._ID, Contacts.DISPLAY_NAME}, null, null, null);
        assertEquals(0, cursor.getCount());
        cursor.close();
 
7
CodeRank
This code example shows how to use the following methods:
    @Override 
    public void setAccount(Account account) { 
        if (account != null) { 
            // TODO: figure out how to infer the contacts account 
            // type from the email account 
            super.setAccount(new android.accounts.Account(account.name, "unknown")); 
        } 
    } 
 
    @Override 
    protected int getDefaultPhotoResource() { 
        return R.drawable.ic_contact_picture; 
    } 
 
    @Override 
    protected int getItemLayout() { 
        return R.layout.chips_recipient_dropdown_item; 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:
                    Bundle result;
                    result = future.getResult();
                    String name = result.getString(AccountManager.KEY_ACCOUNT_NAME);
                    String type = result.getString(AccountManager.KEY_ACCOUNT_TYPE);
                    if (AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), name)) {
                        setAccount(new Account(name, type), false);
                        accountWasSet = true;
                    } 
                } catch (OperationCanceledException e) {
                    Log_OC.d(TAG, "Account creation canceled");
                     
                } catch (Exception e) {
                    Log_OC.e(TAG, "Account creation finished in exception: ", e);
                } 
                     
            } else { 
                Log_OC.e(TAG, "Account creation callback with null bundle");
            } 
            if (!accountWasSet) {
                moveTaskToBack(true); 
6
CodeRank
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
This code example shows how to use the following methods:setIsSyncable, setSyncAutomatically
 
        final String ACCOUNT_NAME = "JavaZone Schedule";
        final String ACCOUNT_TYPE = "no.java.schedule";
        final String PROVIDER = "no.java.schedule";
 
        Account appAccount = new Account(ACCOUNT_NAME,ACCOUNT_TYPE);
        AccountManager accountManager = AccountManager.get(getApplicationContext());
        if (accountManager.addAccountExplicitly(appAccount, null, null)) {
           ContentResolver.setIsSyncable(appAccount, PROVIDER, 1);
           ContentResolver.setSyncAutomatically(appAccount, PROVIDER, true);
        } 
    } 
} 
6
CodeRank

Related Android Account Questions & Answers:

See Code Examples for Android Account Methods: