To get the Android Market Account, I do so:
AccountManager accountManager = AccountManager.get(this);
Account[] accounts = accountManager.getAccountsByType("com.google");
androidCheckout = accounts[0].name.trim().toLowerCase();
With my phone and my credentials the above statement is fine. I've an account so masked: "something@gmail.com".
My question is: I know that the accounts can be either Gmail or Google Apps accounts. And also that Google Apps accounts can have any domain name. So, in this case, instead of @gmail.com there can be everything: depending on the domain name, for instance "cippalippa.us", the account could be "geltrude@cippalippa.us". In this case, the above statement will still be ok??
Account[] accounts = accountManager.getAccountsByType("com.google");
it will work only for google accounts. You can use getAccounts()
instead getAccountsByType()
, now accounts
will be a list of all the sync accounts. You can easily extract your desired account using accounts.name
and accounts.type
来源:https://stackoverflow.com/questions/5055755/getting-android-market-account-programmatically