Reputation: 1138
Is it possible to get email id/ ids which are configured with PlayStore app in android device.
Pattern emailPattern = Patterns.EMAIL_ADDRESS;
Account[] accounts = AccountManager.get(getActivity()).getAccounts();
for (Account account : accounts) {
if (emailPattern.matcher(account.name).matches()) {
primaryEmailID = account.name;
}
}
By using this code I get all sets of email ids configured in device i.e, gmail, yahoo, etc. But how can I get email ids of only gmail account(I guess email ids in gmail account gets configured in playstore).
Upvotes: 0
Views: 2696
Reputation: 1891
public String getMailId() {
String strGmail = null;
try {
Account[] accounts = AccountManager.get(this).getAccounts();
Log.e("PIKLOG", "Size: " + accounts.length);
for (Account account : accounts) {
String possibleEmail = account.name;
String type = account.type;
if (type.equals("com.google")) {
strGmail = possibleEmail;
Log.e("PIKLOG", "Emails: " + strGmail);
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return strGmail;
}
Upvotes: 2
Reputation:
Account[] accounts=AccountManager.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
Upvotes: 0
Reputation: 28073
If you want to access just to Google accounts try using:
AccountManager.get(getActivity()).getAccountsByType("com.google")
Upvotes: 1