问题
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...
回答1:
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).
来源:https://stackoverflow.com/questions/7972642/best-way-to-get-users-android-market-username