diff --git a/zh-cn/application-dev/reference/apis/js-apis-EnterpriseAdminExtensionAbility.md b/zh-cn/application-dev/reference/apis/js-apis-EnterpriseAdminExtensionAbility.md index 49f936f59c1bc974156013c12425da01ceb79c64..e5f4ee612cd8a2d4f78186d9e441b74544de0b9a 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-EnterpriseAdminExtensionAbility.md +++ b/zh-cn/application-dev/reference/apis/js-apis-EnterpriseAdminExtensionAbility.md @@ -49,3 +49,51 @@ export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbil } }; ``` + +## EnterpriseAdminExtensionAbility.onBundleAdded + +onBundleAdded(bundleName: string): void + +应用安装事件回调。 + +**系统能力**:SystemCapability.Customization.EnterpriseDeviceManager + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ----------------------------------- | ---- | ------- | +| bundleName | string | 是 | 安装应用包名。 | + +**示例:** + +```ts +export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility { + onBundleAdded(bundleName: string) { + console.log("added bundle name: " + bundleName); + } +}; +``` + +## EnterpriseAdminExtensionAbility.onBundleRemoved + +onBundleRemoved(bundleName: string): void + +应用卸载事件回调。 + +**系统能力**:SystemCapability.Customization.EnterpriseDeviceManager + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ----------------------------------- | ---- | ------- | +| bundleName | string | 是 | 卸载应用包名。 | + +**示例:** + +```ts +export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility { + onBundleAdded(bundleName: string) { + console.log("removed bundle name: " + bundleName); + } +}; +``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-enterprise-device-manager.md b/zh-cn/application-dev/reference/apis/js-apis-enterprise-device-manager.md index 5fc83540eba1c318e92c183684ad4e33bde099d5..5bc9527c89ef88720539cb86d7b3edfc87690169 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-enterprise-device-manager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-enterprise-device-manager.md @@ -665,6 +665,146 @@ enterpriseDeviceManager.getEnterpriseInfo(wantTemp).then((result) => { }); ``` +## enterpriseDeviceManager.subscribeManagedEvent + +subscribeManagedEvent(admin: Want, managedEvents: Array\, callback: AsyncCallback\): void + +订阅系统管理事件。使用callback异步回调。 + +**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN + +**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ----------------------------------- | ---- | ------- | +| admin | [Want](js-apis-application-Want.md) | 是 | 设备管理员应用。 | +| managedEvents | Array\<[ManagedEvent](#managedevent)> | 是 | 订阅事件数组。 | +| callback | AsyncCallback\ | 是 | 回调函数。当系统管理事件订阅成功err为null,否则为错误对象。 | + +**示例:** + +```js +let wantTemp = { + bundleName: "bundleName", + abilityName: "abilityName", +}; +let events = [0, 1]; +enterpriseDeviceManager.subscribeManagedEvent(wantTemp, events, (error) => { + if (error) { + console.log("error code:" + error.code + " error message:" + error.message); + } +}); +``` + +## enterpriseDeviceManager.subscribeManagedEvent + +subscribeManagedEvent(admin: Want, managedEvents: Array\): Promise\ + +订阅系统管理事件。使用Promise异步回调。 + +**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN + +**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ----------------------------------- | ---- | ------- | +| admin | [Want](js-apis-application-Want.md) | 是 | 设备管理员应用。 | +| managedEvents | Array\<[ManagedEvent](#managedevent)> | 是 | 订阅事件数组。 | + +**返回值:** + +| 类型 | 说明 | +| ----- | ----------------------------------- | +| Promise\ | Promise对象。无返回结果的Promise对象。 | + +**示例:** + +```js +let wantTemp = { + bundleName: "bundleName", + abilityName: "abilityName", +}; +let events = [0, 1]; +enterpriseDeviceManager.subscribeManagedEvent(wantTemp, events).then(() => { +}).catch((error) => { + console.log("error code:" + error.code + " error message:" + error.message); +}) +``` + +## enterpriseDeviceManager.unsubscribeManagedEvent + +unsubscribeManagedEvent(admin: Want, managedEvents: Array\, callback: AsyncCallback\): void + +取消订阅系统管理事件。使用callback异步回调。 + +**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN + +**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ----------------------------------- | ---- | ------- | +| admin | [Want](js-apis-application-Want.md) | 是 | 设备管理员应用。 | +| managedEvents | Array\<[ManagedEvent](#managedevent)> | 是 | 取消订阅事件数组。 | +| callback | AsyncCallback\ | 是 | 回调函数。当系统管理事件取消订阅成功err为null,否则为错误对象。 | + +**示例:** + +```js +let wantTemp = { + bundleName: "bundleName", + abilityName: "abilityName", +}; +let events = [0, 1]; +enterpriseDeviceManager.unsubscribeManagedEvent(wantTemp, events, (error) => { + if (error) { + console.log("error code:" + error.code + " error message:" + error.message); + } +}); +``` + +## enterpriseDeviceManager.unsubscribeManagedEvent + +unsubscribeManagedEvent(admin: Want, managedEvents: Array\): Promise\ + +取消订阅系统管理事件。使用callback异步回调。 + +**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN + +**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ----------------------------------- | ---- | ------- | +| admin | [Want](js-apis-application-Want.md) | 是 | 设备管理员应用。 | +| managedEvents | Array\<[ManagedEvent](#managedevent)> | 是 | 取消订阅事件数组。 | + +**返回值:** + +| 类型 | 说明 | +| ----- | ----------------------------------- | +| Promise\ | Promise对象。无返回结果的Promise对象。 | + +**示例:** + +```js +let wantTemp = { + bundleName: "bundleName", + abilityName: "abilityName", +}; +let events = [0, 1]; +enterpriseDeviceManager.unsubscribeManagedEvent(wantTemp, events).then(() => { +}).catch((error) => { + console.log("error code:" + error.code + " error message:" + error.message); +}) +``` + ## EnterpriseInfo 设备管理员应用的企业信息 @@ -686,3 +826,15 @@ enterpriseDeviceManager.getEnterpriseInfo(wantTemp).then((result) => { | ----------------- | ---- | ----- | | ADMIN_TYPE_NORMAL | 0x00 | 普通管理员 | | ADMIN_TYPE_SUPER | 0x01 | 超级管理员 | + +## ManagedEvent + +可订阅系统管理事件。 + +**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager + +| 名称 | 默认值 | 说明 | +| ----------------- | ---- | ----- | +| MANAGED_EVENT_BUNDLE_ADDED | 0 | 应用安装事件。 | +| MANAGED_EVENT_BUNDLE_REMOVED | 1 | 应用卸载事件。 | +