On the Kindle Fire, is it possible to get a user's email address?
Asked Answered
E

2

7

This question discusses it for android devices in general, but if you try to run this code on a Kindle Fire, all you get is the user's name. Is there any way to get the email address? We were hoping to pop-up a dialog with the email address already pre-filled so they wouldn't have to type it if it were correct, but it seems like the only solution is to have them re-type it.

edit: Here's the code that other threads have suggested (that doesn't work on the 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.
}
Exemplar answered 23/3, 2012 at 23:41 Comment(2)
You haven't found a solution for this, have you? I'm experiencing the issue myselfOrgan
Crap, I was afraid of that... My app was sideloaded by a user on Kindle and only meant for regular Androids and ran into this issue... I guess the only solution will be for me to allow the user to be identified by something other than an email if it's not available...Organ
H
0

On the Kindle Fire, is it possible to get a user's email address?

Sorry, But You totally wrong.

I used to link to Google Login Dialog which show all user existed on 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 GoogleAuthUtil class, might be you need google-oauth-client-1.15.0-rc.jar (Please use the lastest version).

Hausner answered 27/11, 2013 at 14:15 Comment(0)
A
0

On the Fire devices that I have 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.

Anett answered 17/1, 2016 at 12:33 Comment(1)
AccountManager.get(context).getAccountsByType("com.amazon"); returns nothing on my firestickEsculent

© 2022 - 2024 — McMap. All rights reserved.