以编程方式获取 Android Market 帐户

以编程方式获取 Android Market 帐户

问题描述:

为了获得 Android Market 帐户,我这样做:

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();

用我的手机和我的凭据,上面的陈述没问题.我有一个被屏蔽的帐户:something@gmail.com".

With my phone and my credentials the above statement is fine. I've an account so masked: "something@gmail.com".

我的问题是:我知道帐户可以是 Gmail 或 Google Apps 帐户.而且 Google Apps 帐户可以有任何域名.因此,在这种情况下,可以不是@gmail.com,而是一切:根据域名,例如cippalippa.us",帐户可以是geltrude@cippalippa.us".在这种情况下,上面的语句还可以吗??

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");

它仅适用于谷歌帐户.您可以使用 getAccounts() 代替 getAccountsByType(),现在 accounts 将是所有同步帐户的列表.您可以使用 accounts.nameaccounts.type

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