get First Accounts Of - Android Account

Android examples for Account:Account Information

Description

get First Accounts Of

Demo Code


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

import android.content.Context;

import android.text.TextUtils;

public class Main {
    public static Account getFirstAccountsOf(Context context,
            String accountType) {
        if (context == null || TextUtils.isEmpty(accountType)) {
            return null;
        }/*from  w  w  w  .  j av  a 2  s . com*/
        Account[] allAccounts = AccountManager.get(context).getAccounts();
        if (allAccounts == null) {
            return null;
        }
        for (Account account : allAccounts) {
            if (accountType.equals(account.type)) {
                return account;
            }
        }
        return null;
    }
}

Related Tutorials