Last active
December 12, 2015 07:48
-
-
Save jdamcd/4738788 to your computer and use it in GitHub Desktop.
Email adapter for AutoCompleteTextView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ArrayAdapter<String> getEmailAddressAdapter(Context context) { | |
Account[] accounts = AccountManager.get(context).getAccountsByType("com.google"); | |
String[] addresses = new String[accounts.length]; | |
for (int i = 0; i < accounts.length; i++) { | |
addresses[i] = accounts[i].name; | |
} | |
return new ArrayAdapter<String>(context, android.R.layout.simple_dropdown_item_1line, addresses); | |
} |
Nice. Would probably even use an email regex against the account names. There might be some crazy Twitter clients that use account names like "@jdamcd".
Nice.. I came here to suggest exactly the same things, but they're already implemented! 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A small improvement on your idea
private String[] getListOfUserNames(Context context) {
HashSet emailIdsWithoutDuplicates = new HashSet();
Account[] accounts = AccountManager.get(context.getApplicationContext()).getAccounts();
for (int i = 0; i < accounts.length; i++) {
String name = accounts[i].name;
if (name.contains("@")) {
emailIdsWithoutDuplicates.add(name);
}
}
return getArrayFromSet(emailIdsWithoutDuplicates);
}
public static String[] getArrayFromSet(HashSet stringSet) {
return stringSet.toArray(new String[stringSet.size()]);
}