get Account from AccountManager - Android Account

Android examples for Account:Account Information

Description

get Account from AccountManager

Demo Code


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

public class Main {
    public static Account getAccount(Context context, String pattern, int i) {
        AccountManager accountManager = AccountManager.get(context);

        if (accountManager != null) {
            Account[] accounts = accountManager.getAccountsByType(pattern);

            if (accounts != null && accounts.length > i
                    && accounts[i] != null) {
                return accounts[i];
            }//from  w  ww .ja v  a 2s .c  om
        }

        return null;
    }
}

Related Tutorials