Skip to content

Instantly share code, notes, and snippets.

@izmajlowiczl
Created July 29, 2017 21:31
Show Gist options
  • Save izmajlowiczl/70ae740436de124ee027e2599add5533 to your computer and use it in GitHub Desktop.
Save izmajlowiczl/70ae740436de124ee027e2599add5533 to your computer and use it in GitHub Desktop.
// From Plaid app [DesignerNewsLogin.class]
private void setupAccountAutocomplete() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) ==
PackageManager.PERMISSION_GRANTED) {
permissionPrimer.setVisibility(View.GONE);
final Account[] accounts = AccountManager.get(this).getAccounts();
final Set<String> emailSet = new HashSet<>();
for (Account account : accounts) {
if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
emailSet.add(account.name);
}
}
username.setAdapter(new ArrayAdapter<>(this,
R.layout.account_dropdown_item, new ArrayList<>(emailSet)));
} else {
if (shouldShowRequestPermissionRationale(Manifest.permission.GET_ACCOUNTS)) {
setupPermissionPrimer();
} else {
permissionPrimer.setVisibility(View.GONE);
shouldPromptForPermission = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment