How to automatically fill in an email address with the email id with which the device is registered

I want autocomplete emailId EditText with gmail id registered on device. for example, if my phone is registered with the gmail identifier sd@gmail.com , it should be completed automatically when I start entering "s". Any ideas??? Thanks...

+4
source share
2 answers

You need to go through the AccountManager Android class:

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

and also add the necessary permissions for the AndroidManifest file:

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

From there you can autofill information.

+5
source

First set this permission in the AndroidManifest.xml file

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

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); 
+2
source

Source: https://habr.com/ru/post/1401751/


All Articles