How to Get a list of Emails that are available in Gmail app when i want to enter email id in an edittext?
Asked
Active
Viewed 1,007 times
1
-
https://stackoverflow.com/questions/2197741/how-can-i-send-emails-from-my-android-application – pedram shabani Sep 13 '17 at 17:34
2 Answers
0
You cannot achieve this through Edittext, you should use AutoCompleteTextView
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
in you Activity File in onCreate
AutoCompleteTextView autoComplete = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
String selectedEmail;
List<String> emails = new ArrayList<>();
Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
//get runtime permission
Account[] accounts = AccountManager.get(YourActivityName.this).getAccounts();
int i=0;
for (Account account : accounts) {
if (emailPattern.matcher(account.name).matches()) {
String possibleEmail = account.name+"\n";
emails.add(possibleEmail);
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this,android.R.layout.simple_list_item_1,emails);
autoComplete.setAdapter(adapter);
//default selected email
selectedEmail = emails.get(0);
autoComplete.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// You can get the user selected email here
String selectedEmail = emails.get(position)
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
in your manifest you need to add permission
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
if you are developing for API>=23(Marshmallow) then you also need to get runtime permissions. Follow this for runtime permissions
https://developer.android.com/training/permissions/requesting.html

Shriyansh Gautam
- 1,084
- 1
- 7
- 13
-
-
This is my edittext EditText ed3 = (EditText) findViewById(R.id.emailEditText); String e3 = ed3.getText().toString(); and than your code – ykb Sep 13 '17 at 18:59
-
this is not showing any error but it is not working when i click on edittext in my phone. – ykb Sep 13 '17 at 19:02
-
it is not working. But can you help me to reach the course to learn Android Validations.Thank YOU. – ykb Sep 16 '17 at 14:27
0
Anyone looking at this now this feature with this exact dialog is called Sign in Hints!

mbwasi
- 3,612
- 3
- 30
- 36