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!

4

3 回答 3

1

用户在Play 商店中使用的电子邮件帐户应与设备的 Google 帐户相同,您可以通过以下方式获取:

Account[] accounts = accountManager.getAccountsByType("com.google");
于 2013-02-12T00:17:30.143 回答
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;
}

来源:https ://stackoverflow.com/a/2556540/950427

于 2013-02-12T04:50:40.340 回答
0

如果您想获取当前配置为播放商店帐户的帐户邮件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;

            }
        }
于 2015-07-24T10:51:41.490 回答