Android examples for Account:Email Address
get Email Accounts
/******************************************************************************* * Copyright 2013 momock.com/* ww w.j a v a 2s.c o m*/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; import android.util.Patterns; public class Main { public static List<String> getEmailAccounts(Context context) { List<String> emails = new ArrayList<String>(); try { Pattern emailPattern = Patterns.EMAIL_ADDRESS; Account[] accounts = AccountManager.get(context).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { emails.add(account.name); } } } catch (Exception e) { } return emails; } }