1

I am using phonegap and I would like to be able to get the current users email address from either the play store or connect store.

I have tried using this plugin for phonegap: https://github.com/song10/AccountListPlugin

Other than this, I know its not floating around in the DOM so now I am a little stuck.

EDIT

I've found this thread: How to get the Android device's primary e-mail address

Which suggests this:

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

Now to me, as a FrontEnd dev seems like drivle. Still, maybe there is a way in phonegap

Community
  • 1
  • 1
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291

1 Answers1

4

To my knowledge you cannot access it on iOS devices and for Android you can something like the code you shared in your question. There is this for Android and Blackberry if it's something that interests you, but it will not work for iOS.

What you can do:

  • Ask the user for his email (might get fake or invalid email, but there are a few ways to try and avoid it).
  • Use Google+/Facebook sign in and then request permission to read the user's email.

If you can explain further what you are trying to do I might be able to help you tailor a better solution.

I hope it helps. Have a great day.

Assaf Gamliel
  • 11,935
  • 5
  • 41
  • 56
  • Sadly, implementing something on only android wouldn't be too wise as I need a seamless experience between both. Well, the idea behind the wanting the email is so that the user can either click, manual registration or above this have auto register with "xxx@hutber.com" for example. I had had social login buttons, but the nature of the app I don't think people will want to share their details sadly. But more the point, I don't want users thinking that the information will in anyway be linked to social. – Jamie Hutber Jun 18 '14 at 04:38
  • Just let the user enter his email of choice. I feels invasive when your email magically appear the the login or sign up form. Especially inn the context you describe. – Assaf Gamliel Jun 18 '14 at 05:25
  • Ye, I am already letting the user. But I recently installed google chrome and it popuped up, hey xx@blah.com would you like to sign in as this email address. This was a fantastic feature to have. But as you say, maybe because its google and chrome it is trust worthy and not creepy ;) – Jamie Hutber Jun 18 '14 at 05:51
  • Yes although I know a lot of people whom feels the same about Google. The thing with Apple is they keep the privacy of the user locked down so you cant get the email from iOS devices. I'm not sure it was the answer you wanted but I hope it helped. – Assaf Gamliel Jun 18 '14 at 06:00