1

For licensing purposes, I need to know my users' Android Market account, which I believe is the same as the primary account on their device. I can't find a method that does exactly this so instead I query the user's list of google accounts and use the first one:

    AccountManager manager = AccountManager.get(context);
    Account[] accounts = manager.getAccountsByType("com.google");
    String account = "";

    if (accounts != null && accounts.length > 0)
        account = accounts[0].name;

    return account;

This approach seems to work but my question is: is the first account in the array returned by AccountManager.getAccountsByType("com.google") guaranteed to always be the same as their Android Market account, or are there any (non-trivial) exceptions?

Thanks in advance...

Barry Fruitman
  • 12,316
  • 13
  • 72
  • 135
  • user will still be able to change his primary email, log into android market, so using market account for licensing is not that effective – Optimus Nov 01 '11 at 20:48
  • also i don't think there is an actual way to confirm weather or not an account is primary – Optimus Nov 01 '11 at 20:50
  • The only way to change the primary account is to wipe the device so I'm not worried about that. My licensing needs to be reasonably secure but I know no method is perfect. – Barry Fruitman Nov 01 '11 at 20:59
  • I'm running into the same issue, did you come up with a solution? I just need a uid which could be their market account email, but not sure how to enforce it. – citizen conn Nov 24 '11 at 20:54
  • Sorry no, I didn't find a better solution. – Barry Fruitman Nov 26 '11 at 21:33

1 Answers1

2

It used to be the case that the first com.google account registered on a phone was the primary account, and accordingly the account used by Android Market.

Newer versions of Android have done away with the concept of a primary account, and newer versions of Android Market also support multiple accounts.

In summary, there's no longer any difference between the accounts on a phone. All of them may be in use by Android Market simultaneously, and an app may be owned by any one of those accounts (and possibly even several, if the user has bought the app multiple times).

Trevor Johns
  • 15,682
  • 3
  • 55
  • 54