We can create several users and profiles on an Android devices, for example, there is a Main User, and I also set a Work Profile with name "Work Profile".
Using the following adb command:
adb shell pm list users
I'm getting this result:
UserInfo{0:My User:13} running UserInfo{10:Work Profile:30} running
Good, I can see my User Info with the name Work Profile on it. Now, I want to get this list from my application.
I tried to use this code:
for(Account account: AccountManager.get(this).getAccounts()) {
DebugLog.e("COUCOU " + account.name + " " + account.toString());
}
But the Work Profile account is not appearing in the list. Only the main user... Any idea how I could get the same list as the ADB shell command??
You are confusing users with accounts. What you are using will only get you the accounts of the current user.
A device can have multiple users, which are the equivalent of users on a computer.
A user can have multiple accounts, i.e., let that be Gmail, Facebook, Twitter, etc. The accounts may be shared among users or not.
For more info on that topic, check out the official page on Supporting Multiple Users.
You can handle users with UserManager and you can get the list of the profiles of the current user using getUserProfiles, but what you'll get is a UserHandle (which you can use to get the userId), how to get the list of all users and the name is something I haven't found out yet, but on the worst case you can use the shell command pm, as shown in this post about Multiple user accounts on Android.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With