2

I would like to get default email address selected in play store programmatically? I know how to get email address details from account manager but not specifically from play store app? Is this possible?

Thanks!

TheAndroDev
  • 103
  • 1
  • 12

3 Answers3

1

The email account that the user is using in the Play Store should be the same as the Google account for the device, which you can get by using:

Account[] accounts = accountManager.getAccountsByType("com.google");
iTech
  • 18,192
  • 4
  • 57
  • 80
1
static String getEmail(Context context) {
    AccountManager accountManager = AccountManager.get(context); 
    Account account = getAccount(accountManager);

    if (account == null) {
      return null;
    } else {
      return account.name;
    }
}
private static Account getAccount(AccountManager accountManager) {
    Account[] accounts = accountManager.getAccountsByType("com.google");
    Account account;
    if (accounts.length > 0) {
      account = accounts[0];      
    } else {
      account = null;
    }
    return account;
}

Source: https://stackoverflow.com/a/2556540/950427

Community
  • 1
  • 1
Prasanna
  • 236
  • 1
  • 6
  • Will try and get back. But what if there is more than one email address registered to the phone? – TheAndroDev Feb 12 '13 at 16:42
  • It works just fine but problem is how to get the default email address selected in playstore app if multiple accounts are there? – TheAndroDev Feb 13 '13 at 09:26
0

If you want to get the name of account mail id which is configured to play store account currently. Please use it . I am putting here only for email name but you can get all information of account like type , descriptin from account object

 Pattern emailPattern = Patterns.EMAIL_ADDRESS; 
        Account[] accounts =        AccountManager.get(this).getAccountsByType("com.google");
        for (Account account : accounts) {
            if (emailPattern.matcher(account.name).matches()) {
                primaryEmailID = account.name;

            }
        }
Jay Dwivedi
  • 454
  • 3
  • 15