How to get your first Gmail account when we turn on our phone and register it

I have the following code that gets the whole gmail id that is synchronized with my phone, but I want the first gmail id that the user registered for the first time. Since all other gmail accounts (not primary), if I want, I can delete at any time, but delete the main account, we also have to do other things. Therefore, I want the main account to be used in my application.

here is my code, I think, to add some kind of filter to it, I can do it, but I can’t do it right.

Account[] accounts=AccountManager.get(this).getAccountsByType("com.google");
    for(Account account: accounts)
    {
        String possibleEmail=account.name;
        Log.d("Possible email id of user", possibleEmail);
    }

I already saw the Roman link , but could not convert it correctly. I want to use this primary email address for push notification using C2DM from Google.

+2
source share
3 answers

I have an answer, but that was the wrong way to do this. Since I get all the google (gmail) related accounts, and when we enter the email id to synchronize with gmail, the stack is created and at the 0 position I get the main Gmail id that was first entered by the user when he turned it on phone.

    Account[] accounts=AccountManager.get(this).getAccountsByType("com.google");
    String myEmailid=accounts[0].toString();
    Log.d("My email id that i want", myEmailid);
    for(Account account: accounts)
    {
        String possibleEmail=account.toString();
        Log.d("Possible email id of user", possibleEmail);

    }

- , , , , , , ?

+6

, , , . Android 3 " "; , .

+1

- GET_ACCOUNTS....

  private static final int REQUEST_CODE_EMAIL = 1;
        email = (TextView) findViewById(R.id.email);
        ...
        try {
            Intent intent = AccountPicker.newChooseAccountIntent(null, null,
                    new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, false, null, null, null, null);
            startActivityForResult(intent, REQUEST_CODE_EMAIL);
        } catch (ActivityNotFoundException e) {
            // TODO
        }
        ...

    @Override
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        if (requestCode == REQUEST_CODE_EMAIL && resultCode == RESULT_OK) {
            String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            email.setText(accountName);
        }
    }
0
source

All Articles