Example usage for android.os UserManager getUsers

List of usage examples for android.os UserManager getUsers

Introduction

In this page you can find the example usage for android.os UserManager getUsers.

Prototype

@UnsupportedAppUsage
public @NonNull List<UserInfo> getUsers(boolean excludeDying) 

Source Link

Document

Returns information for all users on this device.

Usage

From source file:com.android.tv.settings.users.AppRestrictionsFragment.java

/**
 * Queries for the UserInfo of a user. Returns null if the user doesn't exist (was removed).
 * @param userManager Instance of UserManager
 * @param checkUser The user to check the existence of.
 * @return UserInfo of the user or null for non-existent user.
 *//*from  w  ww  .j  a v a  2 s.c om*/
public static UserInfo getExistingUser(UserManager userManager, UserHandle checkUser) {
    final List<UserInfo> users = userManager.getUsers(true /* excludeDying */);
    final int checkUserId = checkUser.getIdentifier();
    for (UserInfo user : users) {
        if (user.id == checkUserId) {
            return user;
        }
    }
    return null;
}