0

I am testing the following code to get the email registered in the device-

  String gmail = null;
    Pattern gmailPattern = Patterns.EMAIL_ADDRESS;
    Account[] accounts = AccountManager.get(this).getAccounts();
    for (Account account : accounts) {
        if (gmailPattern.matcher(account.name).matches()) {
            gmail = account.name;
        }
    }

This code does not work on Android O until I add the READ_CONTACTS permission.

But It needs the GET_ACCOUNTS permission to work on API 16. and once I add that, for some reason it stops working on android O.

What permissions do I need from what API level to what? My minSdkVersion is 16

user9555243
  • 155
  • 1
  • 3
  • 12
  • go through : https://stackoverflow.com/questions/2112965/how-to-get-the-android-devices-primary-e-mail-address – Sahil May 24 '18 at 17:49
  • I want to minimise the use of permissions and use only the necessary ones – user9555243 May 24 '18 at 17:50
  • @Sahil I did already, and that answer is not accurate as he does not mention the `GET_ACCOUNTS` permission which is necessary on android O – user9555243 May 24 '18 at 17:51

0 Answers0