Getting Android Market Account programmatically

自作多情 提交于 2019-12-10 11:19:33

问题


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??


回答1:


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

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