Q: How to get the Android device's primary e-mail address

D: How do you get the Android's primary e-mail address (or a list of e-mail addresses)?
It's my understanding that on OS 2.0+ there's support for multiple e-mail addresses, but below 2.0 you can only have one e-mail address per device.

Test Case #4


File ID: #2175688-3-cc


Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
Account[] accounts = AccountManager.get(context).getAccounts();
for (Account account : accounts) {
    if (emailPattern.matcher(account.name).matches()) {
        if (null ! = account.name && !"".equals(account.name.trim()) ) {
            return account.name;
        }
    }
}

  1. The profile method is badly flawed (in my opinion). An app that wants/needs my e-mail is not a big deal compared to an app that wants to read all my contacts, but you have made it so that they both require the same permissions. So as a user, I can not tell the difference between an app that is going to read my e-mail, and an app that is going to read my 500+ contacts. This is a very real, practical problem as the number of apps that abuse your contacts is growing!
  2. I agree with on this. Asking permission for the data of the all contacts on the phone for just the First and Last name of the user is ridiculous.
  3. I have similar question using your code i am able to get the all gmail id's associated with my phone but i want the primary one. I found one solution like as we add more mail id's to synchronize with phone it comes into a stack if i am getting the 0th position com.google id's, i am getting the primary one because it enter first and acquire the 0th position in a stack. Here's my some code
    Account[] accounts=AccountManager.get(this).getAccountsByType(""com.google""); 
    	String myEmailid=accounts[0].toString(); 
    	Log.d(""My email id that   i want"", myEmailid);
    i know its not the correct way.

Comments Quality
Accurate?:
Precise?:
Concise?:
Useful?: