4

I basically want to give option to user to select the email ID user wants. I don't want the contacts permission from user. Though account permission is fine with user. I tried answer at stackoverflow but it is not working for me. Is there any other way of getting it?

What I have tried:

Add this permission to manifest:

<uses-permission android:name="android.permission.GET_ACCOUNTS" />

And then request the google accounts like this:

Account[] accounts = AccountManager.get(this).getAccountsByType("com.google");
for (Account account : accounts) {
    Log.d(TAG, "Found: " + account.name);
}
Community
  • 1
  • 1
impossible
  • 2,380
  • 8
  • 36
  • 60

4 Answers4

0

In addition to having the uses-permission line in the manifest, you also have to grant that permission when the app is installed. If you have a new device, it's possible that it's Off. Check the app's permissions in your Settings. That fixed this problem for me.

0

Add one more below permission in manifes. it's working for me. I answered on this question.

<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
PriyankVadariya
  • 809
  • 9
  • 14
0

Add permission in the manifest below android 6.0 else request run time permission

<uses-permission android:name="android.permission.GET_ACCOUNTS" />

Then get accounts using AccountManager.

Account[] accounts = AccountManager.get(context).getAccounts();
Sharath kumar
  • 4,064
  • 1
  • 14
  • 20
-1

Request the google accounts like this:

Pattern emailPattern = Patterns.EMAIL_ADDRESS;
Account[] accounts = AccountManager.get(context).getAccounts();
for (Account account : accounts) {
    if (emailPattern.matcher(account.name).matches()) {
        String emailAccount = account.name;
    }
}
Tony Baby
  • 7,176
  • 6
  • 18
  • 22