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