7

I want to auto-complete an emailId EditText with the gmail-id registered with the device. e.g if my phone is registered with the gmail id sd@gmail.com then it should be auto completed as i start typing "s". Any Ideas??? Thanks...

Shashank Degloorkar
  • 3,151
  • 4
  • 32
  • 50

2 Answers2

5

You have to go through Android AccountManager class:

AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE); 
Account[] list = manager.getAccounts();

and also need to add required permissions to AndroidManifest file:

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

From there you can autofill info.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Mayank
  • 8,777
  • 4
  • 35
  • 60
  • 1
    @Dallas Substantially editing the content of someone else's answer is not appropriate. You may post your content as a new separate answer. Rolling this answer back, do not repeat it. – nobody May 27 '14 at 15:12
  • @AndrewMedico you should probably roll back to the version prior to the major edit, then, as that one had spelling/grammar/syntax fixes. – Dallas May 27 '14 at 19:30
4

Firstly set this permission in your AndroidManifest.xml file

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

The Java code:

//declaration

String possibleEmail="";

//onCreate

EditText emailEdt=new EditText(this);

 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.
    possibleEmail = account.name;

}
emailEdt.setText(possibleEmail);
Ant4res
  • 1,217
  • 1
  • 18
  • 36
Pradeep Sodhi
  • 2,135
  • 1
  • 19
  • 19