to top
Android APIs
public class

UserManager

extends Object
java.lang.Object
   ↳ android.os.UserManager

Class Overview

Manages users and user details on a multi-user system.

Summary

Public Methods
long getSerialNumberForUser(UserHandle user)
Return the serial number for a user.
int getUserCount()
Return the number of users currently created on the device.
UserHandle getUserForSerialNumber(long serialNumber)
Return the user associated with a serial number previously returned by getSerialNumberForUser(UserHandle).
String getUserName()
Returns the user name of the user making this call.
boolean isUserAGoat()
Used to determine whether the user making this call is subject to teleportations.
boolean isUserRunning(UserHandle user)
Return whether the given user is actively running.
boolean isUserRunningOrStopping(UserHandle user)
Return whether the given user is actively running or stopping.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public long getSerialNumberForUser (UserHandle user)

Added in API level 17

Return the serial number for a user. This is a device-unique number assigned to that user; if the user is deleted and then a new user created, the new users will not be given the same serial number.

Parameters
user The user whose serial number is to be retrieved.
Returns
  • The serial number of the given user; returns -1 if the given UserHandle does not exist.

public int getUserCount ()

Added in API level 17

Return the number of users currently created on the device.

public UserHandle getUserForSerialNumber (long serialNumber)

Added in API level 17

Return the user associated with a serial number previously returned by getSerialNumberForUser(UserHandle).

Parameters
serialNumber The serial number of the user that is being retrieved.
Returns
  • Return the user associated with the serial number, or null if there is not one.

public String getUserName ()

Added in API level 17

Returns the user name of the user making this call. This call is only available to applications on the system image; it requires the MANAGE_USERS permission.

Returns
  • the user name

public boolean isUserAGoat ()

Added in API level 17

Used to determine whether the user making this call is subject to teleportations.

Returns
  • whether the user making this call is a goat

public boolean isUserRunning (UserHandle user)

Added in API level 17

Return whether the given user is actively running. This means that the user is in the "started" state, not "stopped" -- it is currently allowed to run code through scheduled alarms, receiving broadcasts, etc. A started user may be either the current foreground user or a background user; the result here does not distinguish between the two.

Parameters
user The user to retrieve the running state for.

public boolean isUserRunningOrStopping (UserHandle user)

Added in API level 17

Return whether the given user is actively running or stopping. This is like isUserRunning(UserHandle), but will also return true if the user had been running but is in the process of being stopped (but is not yet fully stopped, and still running some code).

Parameters
user The user to retrieve the running state for.