Skip to content

Instantly share code, notes, and snippets.

@sierisimo
Created February 14, 2016 07:49
Show Gist options
  • Save sierisimo/4568dc5434a0f71acd09 to your computer and use it in GitHub Desktop.
Save sierisimo/4568dc5434a0f71acd09 to your computer and use it in GitHub Desktop.
Get Email from Android Phone < 6.0
if(userEmail == null || userEmail.trim().isEmpty()) {
boolean flag = false;
Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
Account[] accounts = AccountManager.get(LoginActivity.this).getAccounts();
for (Account account : accounts) {
if (emailPattern.matcher(account.name).matches()) {
userEmail = account.name;
flag = true;
}
}
if(!flag) {
//Do your own stuff to set the email. Like: username+userlastname + "@email.com"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment