0

I want to get and display the users mail accounts list when my apps gets installed .For eg:I am having 3 accounts in my mobile ,when my app get installed it should display three accounts .How can i get the user registered accounts? Any tutorial or link will be advisable.

Deepak
  • 192
  • 1
  • 2
  • 18

1 Answers1

1

You can also use the AccountManager to retrieve the Gmail address entered.

Here is the way I use :

private String getFirstAccount() {
        Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
        Account[] accounts = AccountManager.get(Compte.this).getAccounts();
        for (Account account : accounts) {
            if (emailPattern.matcher(account.name).matches()) {
                String possibleEmail = account.name;
                return possibleEmail;
            }
        }
        return null;
    }
marshallino16
  • 2,645
  • 15
  • 29