Example usage for android.accounts AuthenticatorDescription AuthenticatorDescription

List of usage examples for android.accounts AuthenticatorDescription AuthenticatorDescription

Introduction

In this page you can find the example usage for android.accounts AuthenticatorDescription AuthenticatorDescription.

Prototype

public AuthenticatorDescription(String type, String packageName, int labelId, int iconId, int smallIconId,
            int prefId) 

Source Link

Usage

From source file:edu.cmu.cylab.starslinger.view.SaveActivity.java

@Override
public void onAccountsUpdated(Account[] a) {
    MyLog.i(TAG, "Account list update detected");
    // Clear out any old data to prevent duplicates
    mAccounts.clear();//from  ww  w.ja va  2s.c  o m

    // Get account data from system
    AuthenticatorDescription[] accountTypes = AccountManager.get(this).getAuthenticatorTypes();

    // Also, get a list of all sync adapters and find the ones that
    // support contacts:
    SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes();
    ArrayList<String> contactAccountTypes = new ArrayList<String>();
    for (SyncAdapterType sync : syncs) {
        if (ContactsContract.AUTHORITY.equals(sync.authority) && sync.supportsUploading()) {
            contactAccountTypes.add(sync.accountType);
        }
    }

    // Populate tables
    for (int i = 0; i < a.length; i++) {
        // The user may have multiple accounts with the same name, so we
        // need to construct a
        // meaningful display name for each.
        String systemAccountType = a[i].type;
        AuthenticatorDescription ad = getAuthenticatorDescription(systemAccountType, accountTypes);
        if (ad != null) {
            AccountData data = new AccountData(this, a[i].name, ad);

            // filter on accounts that support contacts
            if (contactAccountTypes.contains(a[i].type))
                mAccounts.add(data);
        }
    }

    // unsync account
    AuthenticatorDescription adNull = new AuthenticatorDescription(mUnsyncType, UNSYNC_PKG, 0, 0, 0, 0);
    AccountData aNull = new AccountData(this, mUnsyncName, adNull);
    mAccounts.add(aNull);

    // Update the account spinner
    mAccountAdapter.notifyDataSetChanged();
}