Udostępnij za pośrednictwem


DevicePolicyManager.AddPersistentPreferredActivity Method

Definition

Called by a profile owner or device owner or holder of the permission android.Manifest.permission#MANAGE_DEVICE_POLICY_LOCK_TASK.

[Android.Runtime.Register("addPersistentPreferredActivity", "(Landroid/content/ComponentName;Landroid/content/IntentFilter;Landroid/content/ComponentName;)V", "GetAddPersistentPreferredActivity_Landroid_content_ComponentName_Landroid_content_IntentFilter_Landroid_content_ComponentName_Handler")]
[Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_LOCK_TASK")]
public virtual void AddPersistentPreferredActivity (Android.Content.ComponentName? admin, Android.Content.IntentFilter? filter, Android.Content.ComponentName activity);
[<Android.Runtime.Register("addPersistentPreferredActivity", "(Landroid/content/ComponentName;Landroid/content/IntentFilter;Landroid/content/ComponentName;)V", "GetAddPersistentPreferredActivity_Landroid_content_ComponentName_Landroid_content_IntentFilter_Landroid_content_ComponentName_Handler")>]
[<Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_LOCK_TASK")>]
abstract member AddPersistentPreferredActivity : Android.Content.ComponentName * Android.Content.IntentFilter * Android.Content.ComponentName -> unit
override this.AddPersistentPreferredActivity : Android.Content.ComponentName * Android.Content.IntentFilter * Android.Content.ComponentName -> unit

Parameters

admin
ComponentName

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

filter
IntentFilter

The IntentFilter for which a default handler is added.

activity
ComponentName

The Activity that is added as default intent handler.

Attributes

Remarks

Called by a profile owner or device owner or holder of the permission android.Manifest.permission#MANAGE_DEVICE_POLICY_LOCK_TASK. to set a default activity that the system selects to handle intents that match the given IntentFilter. This activity will remain the default intent handler even if the set of potential event handlers for the intent filter changes and if the intent preferences are reset.

Note that the caller should still declare the activity in the manifest, the API just sets the activity to be the default one to handle the given intent filter.

The default disambiguation mechanism takes over if the activity is not installed (anymore). When the activity is (re)installed, it is automatically reset as default intent handler for the filter.

The calling device admin must be a profile owner or device owner. If it is not, a security exception will be thrown.

Starting from Build.VERSION_CODES#UPSIDE_DOWN_CAKE, after the persistent preferred activity 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#PERSISTENT_PREFERRED_ACTIVITY_POLICY<li> The additional policy params bundle, which contains PolicyUpdateReceiver#EXTRA_INTENT_FILTER the intent filter the policy applies to <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.

NOTE: Performs disk I/O and shouldn't be called on the main thread.

Java documentation for android.app.admin.DevicePolicyManager.addPersistentPreferredActivity(android.content.ComponentName, android.content.IntentFilter, android.content.ComponentName).

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