Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import android.util.Patterns;

import java.util.ArrayList;

import java.util.regex.Pattern;

public class Main {
    public static void getEmails(Context context) {
        Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
        Account[] accounts = AccountManager.get(context.getApplicationContext()).getAccounts();
        String possibleEmails;
        ArrayList<String> emails = new ArrayList<>();
        for (Account account : accounts) {
            if (emailPattern.matcher(account.name).matches()) {
                possibleEmails = account.name;
                emails.add(possibleEmails);
            }
        }
    }
}