Lollipop - Device's users management

498 views Asked by At

In Android Lollipop, is it possible to retrieve the list of Users in a device? I'm speaking of those selected by pressing the user's profile pic in the quicksetting drawer.

What other actions can we take on these users?

  • Retrieve list of users?
  • Retrieve user's profile pic?
  • Change from one user to another?
  • At least use an Intent to open the default usesr management page?
1

There are 1 answers

0
Pieter Meiresone On

Lots of information can be found in the UserManager object. This class manages users and user details on a multi-user system.

This class has a method getUserProfiles which returns a list of UserHandles for profiles associated with the user that the calling process is running on, including the user itself. A UserHandle is a representation of a user on the device.

Another useful class is DevicePolicyManager. To switch between users you can use switchUser in DevicePolicyManager

This is also described here, where the new Android 5.0 API's are explained.

To open the default user management page, you can use this Intent:

Intent intent = new Intent("android.settings.USER_SETTINGS");
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(intent);
}

I can't find official documentation for this action, but you can verify this in the source code. I have also tested this on Android 5.0.