This question一般会讨论Android设备,但是如果你试图在Kindle Fire上运行这个代码,你得到的就是用户的名字.有没有办法获得电子邮件地址?我们希望弹出一个已预先填充的电子邮件地址的对话框,这样如果它是正确的,他们就不必输入它,但似乎唯一的解决方案是让它们重新输入它.
编辑:这是其他线程建议的代码(在Kindle Fire上不起作用):
Account[] accounts = AccountManager.get(this).getAccounts(); for (Account account : accounts) { // TODO: Check possibleEmail against an email regex or treat // account.name as an email address only for certain account.type values. String possibleEmail = account.name; // possibleEmail is a list of account names,hopefully including the @gmail.com address. }
解决方法
On the Kindle Fire,is it possible to get a user’s email address?
对不起,但你完全错了.
我以前链接到Google登录对话框,显示Kindle Fire上存在的所有用户.
请遵循以下代码:
public class AuthAcount { private Context context; private AccountManager mAccountManager; public AuthAcount(Context context) { setContext(context); } public Account[] getAccount() { mAccountManager = AccountManager.get(context); Account[] accounts = mAccountManager .getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE); return accounts; } public Context getContext() { return context; } public void setContext(Context context) { this.context = context; } }
P / s:要使用GoogleAuthUtil类,可能需要google-oauth-client-1.15.0-rc.jar(请使用最新版本).