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.