次の方法で共有


DevicePolicyManager.CreateAndManageUser Method

Definition

Called by a device owner to create a user with the specified name and a given component of the calling package as profile owner.

[Android.Runtime.Register("createAndManageUser", "(Landroid/content/ComponentName;Ljava/lang/String;Landroid/content/ComponentName;Landroid/os/PersistableBundle;I)Landroid/os/UserHandle;", "GetCreateAndManageUser_Landroid_content_ComponentName_Ljava_lang_String_Landroid_content_ComponentName_Landroid_os_PersistableBundle_IHandler", ApiSince=24)]
public virtual Android.OS.UserHandle? CreateAndManageUser (Android.Content.ComponentName admin, string name, Android.Content.ComponentName profileOwner, Android.OS.PersistableBundle? adminExtras, Android.App.Admin.UserManagementFlags flags);
[<Android.Runtime.Register("createAndManageUser", "(Landroid/content/ComponentName;Ljava/lang/String;Landroid/content/ComponentName;Landroid/os/PersistableBundle;I)Landroid/os/UserHandle;", "GetCreateAndManageUser_Landroid_content_ComponentName_Ljava_lang_String_Landroid_content_ComponentName_Landroid_os_PersistableBundle_IHandler", ApiSince=24)>]
abstract member CreateAndManageUser : Android.Content.ComponentName * string * Android.Content.ComponentName * Android.OS.PersistableBundle * Android.App.Admin.UserManagementFlags -> Android.OS.UserHandle
override this.CreateAndManageUser : Android.Content.ComponentName * string * Android.Content.ComponentName * Android.OS.PersistableBundle * Android.App.Admin.UserManagementFlags -> Android.OS.UserHandle

Parameters

admin
ComponentName

Which DeviceAdminReceiver this request is associated with.

name
String

The user's name.

profileOwner
ComponentName

Which DeviceAdminReceiver will be profile owner. Has to be in the same package as admin, otherwise no user is created and an IllegalArgumentException is thrown.

adminExtras
PersistableBundle

Extras that will be passed to onEnable of the admin receiver on the new user.

flags
UserManagementFlags

#SKIP_SETUP_WIZARD, #MAKE_USER_EPHEMERAL and #LEAVE_ALL_SYSTEM_APPS_ENABLED are supported.

Returns

the android.os.UserHandle object for the created user, or null if the user could not be created.

Attributes

Remarks

Called by a device owner to create a user with the specified name and a given component of the calling package as profile owner. The UserHandle returned by this method should not be persisted as user handles are recycled as users are removed and created. If you need to persist an identifier for this user, use UserManager#getSerialNumberForUser. The new user will not be started in the background.

admin is the DeviceAdminReceiver which is the device owner. profileOwner is also a DeviceAdminReceiver in the same package as admin, and will become the profile owner and will be registered as an active admin on the new user. The profile owner package will be installed on the new user.

If the adminExtras are not null, they will be stored on the device until the user is started for the first time. Then the extras will be passed to the admin when onEnable is called.

From android.os.Build.VERSION_CODES#P onwards, if targeting android.os.Build.VERSION_CODES#P, throws UserOperationException instead of returning null on failure.

Java documentation for android.app.admin.DevicePolicyManager.createAndManageUser(android.content.ComponentName, java.lang.String, android.content.ComponentName, android.os.PersistableBundle, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to