Share via


DevicePolicyManager.AddUserRestrictionGlobally(String) Method

Definition

Called by a profile owner, device owner or a holder of any permission that is associated with a user restriction to set a user restriction specified by the provided key globally on all users.

[Android.Runtime.Register("addUserRestrictionGlobally", "(Ljava/lang/String;)V", "GetAddUserRestrictionGlobally_Ljava_lang_String_Handler", ApiSince=34)]
public virtual void AddUserRestrictionGlobally (string key);
[<Android.Runtime.Register("addUserRestrictionGlobally", "(Ljava/lang/String;)V", "GetAddUserRestrictionGlobally_Ljava_lang_String_Handler", ApiSince=34)>]
abstract member AddUserRestrictionGlobally : string -> unit
override this.AddUserRestrictionGlobally : string -> unit

Parameters

key
String

The key of the restriction.

Attributes

Remarks

Called by a profile owner, device owner or a holder of any permission that is associated with a user restriction to set a user restriction specified by the provided key globally on all users. To clear the restriction use #clearUserRestriction.

For a given user, a restriction will be set if it was applied globally or locally by any admin.

The calling device admin must be a profile owner, device owner or or a holder of any permission that is associated with a user restriction; if it is not, a security exception will be thrown.

See the constants in android.os.UserManager for the list of restrictions that can be enforced device-wide. These constants will also state in their documentation which permission is required to manage the restriction using this API.

After the user restriction 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 returned from DevicePolicyIdentifiers#getIdentifierForUserRestriction(String)<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.

Java documentation for android.app.admin.DevicePolicyManager.addUserRestrictionGlobally(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