Search code examples
androidgmailgoogle-play-services

Get Email Id of device which is configured with PlayStore


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).


Solution

  • If you want to access just to Google accounts try using:

    AccountManager.get(getActivity()).getAccountsByType("com.google")