Best way to get user's Android Market username

妖精的绣舞 提交于 2020-01-15 16:39:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!