Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

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

import android.content.Context;

import android.util.Patterns;

import java.util.regex.Pattern;

public class Main {
    public static String getEmailAccount(Context context) {
        try {
            Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
            Account[] accounts = AccountManager.get(context).getAccounts();
            for (Account account : accounts) {
                if (emailPattern.matcher(account.name).matches()) {
                    String possibleEmail = account.name;
                    return possibleEmail;
                }
            }
        } catch (Exception e) {
        }
        return null;
    }
}