TheAndroDev
TheAndroDev

Reputation: 103

Get default email address from playstore app

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!

Upvotes: 2

Views: 2385

Answers (3)

Jay Dwivedi
Jay Dwivedi

Reputation: 464

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;

            }
        }

Upvotes: 0

Prasanna
Prasanna

Reputation: 236

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

Upvotes: 1

iTech
iTech

Reputation: 18460

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");

Upvotes: 1

Related Questions