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