Java tutorial
//package com.java2s; //License from project: Open Source License import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; import android.util.Patterns; import java.util.ArrayList; import java.util.List; public class Main { public static List<String> getUserEmailAccounts(Context context) { // get all accounts listed in the phone List<String> accountSet = new ArrayList<>(); // match with email address pattern and add to set to avoid duplicates Account[] accounts = AccountManager.get(context).getAccounts(); for (Account account : accounts) { if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) { accountSet.add(account.name); } } return accountSet; } }