Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find Gmail account associated with Android Market?

I know how to find accounts (which will include gmail email ids of user) and how to filter gmail account.

AccountManager am = AccountManager.get(context);
        Account[] accounts = am.getAccounts();
        ArrayList<String> googleAccounts = new ArrayList<String>();
        for (Account ac : accounts) {
            String acname = ac.name;
            String actype = ac.type;
            //add only google accounts
            if(ac.type.equals("com.google")) {
                googleAccounts.add(ac.name);
            }
            Log.d(TAG, "accountInfo: " + acname + ":" + actype);
        }
        return googleAccounts;

What I wish to know is how to find the gmail account associated with Android Market? If you will try to delete a gmail account from Android phone you will get this message enter image description here

but if you try to delete a gmail account associated with Android Market you will get the following message (if you press remove account in the earlier message).

enter image description here

Thanks for the help.

like image 447
Gaurav Agarwal Avatar asked May 15 '12 18:05

Gaurav Agarwal


People also ask

How can I tell which Gmail Accounts are linked?

Go to the Google app where you linked the third-party account with your Google Account. For example, the Google Home app, the Google Assistant app, or the YouTube app. Select Connected accounts, Linked accounts, or Apps. This may be in the Google app's Settings section.

How do I find what Gmail Accounts My mobile number is linked to?

Hi there, You are the only one who can know how many accounts you have created with your phone number. Google cannot provide such information under any circumstances. In case you want to see all email addresses connected to your Google account please go to https://myaccount.google.com/email.

Where do I find Accounts on Android?

Open your phone's Settings app. Tap Passwords & accounts. If you don't see "Accounts," tap Users & accounts.


2 Answers

From what I have found, the first google account added in the device is the primary google address which is associated with android market. Also, we get google accounts in the order it was added in the device. So, accounts[0] will be the first email-Id added.

String marketAssociatedEmailId = "";
Account[] accounts = AccountManager.get(context).getAccountsByType("com.google");
if(accounts.length > 0) {
  marketAssociatedEmailId = accounts[0].name;
}

Again, I am not sure about this. You have to test it yourself with various scenarios.

like image 94
Hemanth Avatar answered Sep 19 '22 15:09

Hemanth


The dialog

enter image description here

is caused by the implementation of AbstractAccountAuthenticator#getAccountRemovalAllowed in the Google account authenticator.

Since calling implementations of AbstractAccountAuthenticator directly is prevented by the system-only permission android.permission.ACCOUNT_MANAGER you're going to have a hard time finding this out on your own.

like image 43
Jens Avatar answered Sep 19 '22 15:09

Jens