Best way to get Android Market username

For licensing purposes, I need to know the account of my Android Android server, which I believe is the same as the main account on their device. I can't find a method that does exactly that, so instead I request a 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") guarantee to always be the same as the Android Market account, or is there some ( non-trivial) exceptions?

Thanks in advance...

+1
source share
1 answer

It so happened that the first com.google account registered on the phone was the main account and, accordingly, the account used by the Android Market.

Newer versions of Android do away with the concept of a main account, while newer versions of the Android Market also support multiple accounts.

Thus, there is no longer a difference between the accounts on the phone. All of them can be used by the Android Market at the same time, and the application can belong to any of these accounts (and possibly even several if the user bought the application several times).

+2
source

Source: https://habr.com/ru/post/1389067/


All Articles