Share via


DevicePolicyManager.SetLockTaskPackages(ComponentName, String[]) Method

Definition

Sets which packages may enter lock task mode.

[Android.Runtime.Register("setLockTaskPackages", "(Landroid/content/ComponentName;[Ljava/lang/String;)V", "GetSetLockTaskPackages_Landroid_content_ComponentName_arrayLjava_lang_String_Handler")]
[Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_LOCK_TASK")]
public virtual void SetLockTaskPackages (Android.Content.ComponentName? admin, string[] packages);
[<Android.Runtime.Register("setLockTaskPackages", "(Landroid/content/ComponentName;[Ljava/lang/String;)V", "GetSetLockTaskPackages_Landroid_content_ComponentName_arrayLjava_lang_String_Handler")>]
[<Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_LOCK_TASK")>]
abstract member SetLockTaskPackages : Android.Content.ComponentName * string[] -> unit
override this.SetLockTaskPackages : Android.Content.ComponentName * string[] -> unit

Parameters

admin
ComponentName

Which DeviceAdminReceiver this request is associated with. Null if the caller is not a device admin.

packages
String[]

The list of packages allowed to enter lock task mode

Attributes

Exceptions

Remarks

Sets which packages may enter lock task mode.

Any packages that share uid with an allowed package will also be allowed to activate lock task. From android.os.Build.VERSION_CODES#M removing packages from the lock task package list results in locked tasks belonging to those packages to be finished.

This function can only be called by the device owner, a profile owner of an affiliated user or profile, or the profile owner when no device owner is set or holders of the permission android.Manifest.permission#MANAGE_DEVICE_POLICY_LOCK_TASK. See #isAffiliatedUser. Any package set via this method will be cleared if the user becomes unaffiliated.

Starting from Build.VERSION_CODES#UPSIDE_DOWN_CAKE, after the lock task policy has been set, PolicyUpdateReceiver#onPolicySetResult(Context, String, Bundle, TargetUser, PolicyUpdateResult) will notify the admin on whether the policy was successfully set or not. This callback will contain: <ul> <li> The policy identifier DevicePolicyIdentifiers#LOCK_TASK_POLICY<li> The TargetUser that this policy relates to <li> The PolicyUpdateResult, which will be PolicyUpdateResult#RESULT_POLICY_SET if the policy was successfully set or the reason the policy failed to be set (e.g. PolicyUpdateResult#RESULT_FAILURE_CONFLICTING_ADMIN_POLICY) </ul> If there has been a change to the policy, PolicyUpdateReceiver#onPolicyChanged(Context, String, Bundle, TargetUser, PolicyUpdateResult) will notify the admin of this change. This callback will contain the same parameters as PolicyUpdateReceiver#onPolicySetResult and the PolicyUpdateResult will contain the reason why the policy changed.

Starting from Build.VERSION_CODES#UPSIDE_DOWN_CAKE, lock task features and lock task packages are bundled as one policy. A failure to apply one will result in a failure to apply the other.

Java documentation for android.app.admin.DevicePolicyManager.setLockTaskPackages(android.content.ComponentName, java.lang.String[]).

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

See also

  • StartLockTask()
  • <xref:Android.App.Admin.DeviceAdminReceiver.OnLockTaskModeEntering(Android.Content.Context%2c+Android.Content.Intent%2c+Android.Content.Intent)>
  • <xref:Android.App.Admin.DeviceAdminReceiver.OnLockTaskModeExiting(Android.Content.Context%2c+Android.Content.Intent)>
  • DisallowCreateWindows