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!
用户在Play 商店中使用的电子邮件帐户应与设备的 Google 帐户相同,您可以通过以下方式获取:
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;
}
如果您想获取当前配置为播放商店帐户的帐户邮件ID的名称。请使用它。我在这里仅用于电子邮件名称,但您可以从帐户对象中获取帐户的所有信息,例如类型,描述
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;
}
}