get All Accounts Of - Android Account

Android examples for Account:Account Information

Description

get All Accounts Of

Demo Code


//package com.java2s;
import android.accounts.Account;
import android.accounts.AccountManager;

import android.content.Context;

import android.text.TextUtils;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<Account> getAllAccountsOf(Context context,
            String accountType) {
        List<Account> accounts = new ArrayList<Account>();
        if (context == null || TextUtils.isEmpty(accountType)) {
            return accounts;
        }/*from w w w . ja va  2  s.c  o m*/
        Account[] allAccounts = AccountManager.get(context).getAccounts();
        if (allAccounts == null) {
            return accounts;
        }
        for (Account account : allAccounts) {
            if (accountType.equals(account.type)) {
                accounts.add(account);
            }
        }
        return accounts;
    }
}

Related Tutorials