Can I get a user's email address on the Kindle Fire?

This question discusses it for Android devices in general, but if you try to run this code on the Kindle Fire, all you get is the username. Is there a way to get an email address? We were hoping to pop up a dialog with an already filled in email address, so they would not have to enter it if it was correct, but it seems that the only solution is to reuse them.

edit: Here is the code suggested by other threads (which doesn't work on 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. } 
+7
source share
2 answers

Can I get a user's email address on the Kindle Fire?

Sorry, but you are completely wrong.

I is used to link to the Google Login Dialog, which shows all the users that existed on the Kindle Fire.

Please follow this code:

 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: to use the GoogleAuthUtil class, you may need google-oauth-client-1.15.0-rc.jar (use the latest version).

0
source

On Fire devices that are available to me, this is what I did:

 final static String TYPE_GOOGLE = "com.google"; final static String TYPE_AMAZON = "com.amazon"; final static String AMAZON_EMAIL = "com.amazon.pim"; public static String getAccountName(final Context context) { boolean amazon = TextUtils.equals(Build.MANUFACTURER, "Amazon"); String type = amazon ? TYPE_AMAZON : TYPE_GOOGLE; String email = null; try { Account acc[] = AccountManager.get(context).getAccountsByType(type); if (acc.length > 0) { email = acc[0].name; for (int i = 0; i < acc.length; i++) { Account account = acc[i]; if (amazon) { // there are a lot of flags, just skip them if (!TextUtils.equals(account.type, TYPE_AMAZON)) { // is it an email account? if (account.type.startsWith(AMAZON_EMAIL)) { email = account.name; } } } } } else { acc = AccountManager.get(context).getAccounts(); if (acc.length > 0) { // just return the first one... email = acc[0].name; } } } catch (Exception ex) { ex.printStackTrace(); } return email; } 

This will also work with Google Play devices.

0
source

All Articles