Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto fill the email edittext with the email id by which the device is registered

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 [email protected] then it should be auto completed as i start typing "s". Any Ideas??? Thanks...

like image 352
Shashank Degloorkar Avatar asked Mar 16 '12 07:03

Shashank Degloorkar


People also ask

How do I get autofill on my phone?

Users can enable or disable autofill as well as change the autofill service by navigating to Settings > System > Languages & input > Advanced > Input assistance > Autofill service.

What is autofill developer options?

Autofill is a dedicated framework introduced by Google that manages communication between the autofill service and apps on your Android device. The service works much like password managers, which take the stress out of forgetting passwords and fills out information in other apps using your data.


2 Answers

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.

like image 124
Mayank Avatar answered Oct 16 '22 22:10

Mayank


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);
like image 43
Pradeep Sodhi Avatar answered Oct 16 '22 21:10

Pradeep Sodhi