共用方式為


DevicePolicyManager.GrantKeyPairToApp(ComponentName, String, String) Method

Definition

Called by a device or profile owner, or delegated certificate chooser (an app that has been delegated the #DELEGATION_CERT_SELECTION privilege), to grant an application access to an already-installed (or generated) KeyChain key.

[Android.Runtime.Register("grantKeyPairToApp", "(Landroid/content/ComponentName;Ljava/lang/String;Ljava/lang/String;)Z", "GetGrantKeyPairToApp_Landroid_content_ComponentName_Ljava_lang_String_Ljava_lang_String_Handler", ApiSince=30)]
public virtual bool GrantKeyPairToApp (Android.Content.ComponentName? admin, string alias, string packageName);
[<Android.Runtime.Register("grantKeyPairToApp", "(Landroid/content/ComponentName;Ljava/lang/String;Ljava/lang/String;)Z", "GetGrantKeyPairToApp_Landroid_content_ComponentName_Ljava_lang_String_Ljava_lang_String_Handler", ApiSince=30)>]
abstract member GrantKeyPairToApp : Android.Content.ComponentName * string * string -> bool
override this.GrantKeyPairToApp : Android.Content.ComponentName * string * string -> bool

Parameters

admin
ComponentName

Which DeviceAdminReceiver this request is associated with, or null if calling from a delegated certificate chooser.

alias
String

The alias of the key to grant access to.

packageName
String

The name of the (already installed) package to grant access to.

Returns

true if the grant was set successfully, false otherwise.

Attributes

Remarks

Called by a device or profile owner, or delegated certificate chooser (an app that has been delegated the #DELEGATION_CERT_SELECTION privilege), to grant an application access to an already-installed (or generated) KeyChain key. This is useful (in combination with #installKeyPair or #generateKeyPair) to let an application call android.security.KeyChain#getPrivateKey without having to call android.security.KeyChain#choosePrivateKeyAlias first.

The grantee app will receive the android.security.KeyChain#ACTION_KEY_ACCESS_CHANGED broadcast when access to a key is granted.

Starting from android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE throws an IllegalArgumentException if alias doesn't correspond to an existing key.

Java documentation for android.app.admin.DevicePolicyManager.grantKeyPairToApp(android.content.ComponentName, java.lang.String, 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