Get number of account in android accountManager. - Android Account

Android examples for Account:Account Information

Description

Get number of account in android accountManager.

Demo Code


//package com.java2s;

import android.accounts.Account;
import android.accounts.AccountManager;

import android.content.Context;

public class Main {
    /**//w  w w  . ja  va2  s  .  c om
     * Get number of account in android accountManager.
     * 
     * @param context
     * @param accountType
     * @return Number of accounts
     */
    public static Integer getNumberOfAccounts(final Context context,
            String accountType) {
        return getAccounts(context, accountType).length;
    }

    /**
     * Get all registered accounts from system
     * 
     * @param context
     * @return array of accounts
     */
    public static Account[] getAccounts(final Context context,
            String accountType) {
        return AccountManager.get(context).getAccountsByType(accountType);
    }
}

Related Tutorials