I want get account list in Android 8.1. I make:
- Add permition in manifect:
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
- Request permition from user.
- Check permition and get account list:
// account
Context mContext = App.Companion.getInstance();
int permissionStatus = ContextCompat.checkSelfPermission(mContext, Manifest.permission.GET_ACCOUNTS);
if (permissionStatus == PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "hasAccount: Have permission" );
AccountManager accountManager = AccountManager.get(mContext);
Account[] accounts = accountManager.getAccounts();
if (accounts.length > 0) {
result.put("hasAccount", true);
} else {
result.put("hasAccount", false);
}
}
else {
Log.e(TAG, "hasAccount: Have not permission!" );
result.put("hasAccount", true);
}
In log: D/SecureService: hasAccount: Have permission and in accounts = []. Why android return entry account list? I have account in phone:

From Android 8.0, GET_ACCOUNTS is no longer sufficient to access the Accounts on device.
Based on the documentation:
In Android 8.0 (API level 26), apps can no longer get access to user accounts unless the authenticator owns the accounts or the user grants that access. The GET_ACCOUNTS permission is no longer sufficient. To be granted access to an account, apps should either use AccountManager.newChooseAccountIntent() or an authenticator-specific method. After getting access to accounts, an app can call AccountManager.getAccounts() to access them.
You can check this link for usage of AccountManager.newChooseAccountIntent()