2

I have seen in other question how to get the device emails, but I need to get the email of the current user

I'm implementing in-App billing and need to know what is the email of the user for security check, so the email that I must get must be the same currently used for his GooglePlay account and this method doesn't sound very reliable for this purpose

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

A smartphone could have more accounts saved and I haven't understood how could I know what is the current account active between the various accounts in list.

AndreaF
  • 11,975
  • 27
  • 102
  • 168
  • I've never tried it myself, but [here's something that looks promising](https://developers.google.com/+/mobile/android/people#retrieve_an_authenticated_users_email_address). Alternatively, in stead of automatically selecting a particular account, you could [invoke the `AccountPicker`](http://developer.android.com/google/auth/http-auth.html#AccountPicker) and let the user choose the desired account. – MH. Sep 27 '14 at 14:15
  • 1
    Thanks but since I need the account email for a security check I should check the email of current active account automatically without the user intervention. – AndreaF Sep 27 '14 at 14:25
  • @AndreaF: we have your same issue. Have you found a solution? – SagittariusA Mar 24 '16 at 12:10

0 Answers0