I have to fetch logged in email. I am trying to fetch using AccountManager. Here is my code
private void getEmails() {
Pattern emailPattern = Patterns.EMAIL_ADDRESS;
// Getting all registered Google Accounts;
Account[] accounts = AccountManager.get(this).getAccountsByType("com.google");
// Getting all registered Accounts;
// Account[] accounts = AccountManager.get(this).getAccounts();
for (Account account : accounts) {
if (emailPattern.matcher(account.name).matches()) {
Log.d(TAG, String.format("%s - %s", account.name, account.type));
}
}
}
I tried both option AccountManager.get(this).getAccountsByType("com.google"); AccountManager.get(this).getAccounts();
Both are returning empty body.
Please help me.