0

As topic says. I want to get the email a user has registered on their phone to log on into android market. This due to the fact that my application connects to a remote database that´s supposed to store who have done a specific thing in the app..

I´ve searched the web for similar problems, but i have´nt found a possible solution yet.. :/

Does anyone have a nice codesnippet that shows how to do this?

Thanks in advance!

/ Alex

  • 2
    Hmm, hopefully there's some laws on data protection that'd prevent the email address from being available without prompting the user for it ... I understand your want/need to have a user unique identifier (UUID) but that doesn't have to / shouldn't be the email address. See http://stackoverflow.com/questions/2322234 – FrankH. Dec 17 '10 at 14:04

2 Answers2

2

You want AccountManager

Account[] accounts = AccountManager.get(this).getAccounts();

for (Account account : accounts) {
  // TODO: Check possibleEmail against an email regex or treat
  // account.name as an email address only for certain account.type values.
  String possibleEmail = account.name;
  ...
}

But AFAIK, there is no way to see which one is being used in the market. Assume that the first gmail account (use regex) would likely hit 99% of users.

Richard Taylor
  • 2,702
  • 2
  • 22
  • 44
  • Okay. I´ve seen that codesnippet already and it returns the users firstname and surname only. Thanks for a superfast answer though! – Alexander Dec 17 '10 at 14:16
2

Due to security issues, you will not be able to just "get" that info. You have to ask for it from the user. That is why they implemented the "authentication tokens", so you don't need to know their email, you just store the token.

Ryan Conrad
  • 6,870
  • 2
  • 36
  • 36