Created
February 14, 2016 07:49
-
-
Save sierisimo/4568dc5434a0f71acd09 to your computer and use it in GitHub Desktop.
Get Email from Android Phone < 6.0
This file contains 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
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