0

I want to fetch list of email addresses from user's email client in my android app. So, that before sending an email through app user is presented with the list of email addresses and he can just select the ones he want to send the email.

I am aware of AccountManager and Account classes which gives user account info. But I don't know how to get the list of email addresses? Please help..

Thanks in advance.

Sheetal Jadhwani
  • 75
  • 1
  • 3
  • 9

1 Answers1

1

Try the following:

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;
        ...
    }
}

Note that this requires the GET_ACCOUNTS permission:

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
fida1989
  • 3,234
  • 1
  • 27
  • 30