0

I want to automatically add device primary gmail id in the edit text field whenever user open the login page.

this is my emailview

mEmailView = (EditText)findViewById(R.id.account_email);

I have mentioned the permission in the Main fest

<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>

any suggestion ?

NITIN DUDA
  • 192
  • 1
  • 14
  • @Floem I just want the email address like copy and paste, copy the device primary email and paste it to my emailview edittext field. – NITIN DUDA Nov 23 '14 at 07:04

1 Answers1

1

Answer for my question simple and easy way to put device email into edittext

    mEmailView = (EditText)findViewById(R.id.email);
    Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
    android.accounts.Account[] accounts = AccountManager.get(getBaseContext()).getAccounts();
    for (android.accounts.Account account : accounts) {
    if (emailPattern.matcher(account.name).matches()) {
    possibleEmail = account.name;
    }
    }


    TextView t1 = (TextView)findViewById(R.id.account_email);
    t1.setText(possibleEmail);
NITIN DUDA
  • 192
  • 1
  • 14