在android 4.2中获取多个用户

时间:2013-02-08 11:15:43

标签: android

有没有办法找到设备中配置的用户列表(android 4.2+)?

谢谢, Jeyanthi

1 个答案:

答案 0 :(得分:1)

好。如果您看到UserManager.java源代码,则可以找到这些方法。 Hovewer,这些方法需要android.permission.MANAGE_USERS

MANAGE_USERS具有签名系统的保护级别,这意味着必须使用平台密钥对应用程序进行签名。

/**
     * Returns information for all users on this device.
     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
     * @return the list of users that were created.
     * @hide
     */
    public List<UserInfo> getUsers() {
        try {
            return mService.getUsers(false);
        } catch (RemoteException re) {
            Log.w(TAG, "Could not get user list", re);
            return null;
        }
    }

    /**
     * Returns information for all users on this device.
     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
     * @param excludeDying specify if the list should exclude users being removed.
     * @return the list of users that were created.
     * @hide
     */
    public List<UserInfo> getUsers(boolean excludeDying) {
        try {
            return mService.getUsers(excludeDying);
        } catch (RemoteException re) {
            Log.w(TAG, "Could not get user list", re);
            return null;
        }
    }