未验证 提交 6865f3d4 编写于 作者: O openharmony_ci 提交者: Gitee

!23501 【EDM】ArkTS编码规范整改

Merge pull request !23501 from 李兀立/master
...@@ -40,7 +40,6 @@ onBundleRemoved: 企业应用管理场景下,企业管理员订阅应用卸载 ...@@ -40,7 +40,6 @@ onBundleRemoved: 企业应用管理场景下,企业管理员订阅应用卸载
import EnterpriseAdminExtensionAbility from '@ohos.enterprise.EnterpriseAdminExtensionAbility'; import EnterpriseAdminExtensionAbility from '@ohos.enterprise.EnterpriseAdminExtensionAbility';
export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility { export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
onAdminEnabled() { onAdminEnabled() {
console.info("onAdminEnabled"); console.info("onAdminEnabled");
} }
...@@ -50,18 +49,18 @@ export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbil ...@@ -50,18 +49,18 @@ export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbil
} }
onBundleAdded(bundleName: string) { onBundleAdded(bundleName: string) {
console.info("EnterpriseAdminAbility onBundleAdded bundleName:" + bundleName) console.info("EnterpriseAdminAbility onBundleAdded bundleName:" + bundleName);
} }
onBundleRemoved(bundleName: string) { onBundleRemoved(bundleName: string) {
console.info("EnterpriseAdminAbility onBundleRemoved bundleName" + bundleName) console.info("EnterpriseAdminAbility onBundleRemoved bundleName" + bundleName);
} }
}; };
``` ```
​ 4.在工程Module对应的[module.json5](../quick-start/module-configuration-file.md)配置文件中注册ServiceExtensionAbility,type标签需要设置为“enterpriseAdmin”,srcEntry标签表示当前ExtensionAbility组件所对应的代码路径。 ​ 4.在工程Module对应的[module.json5](../quick-start/module-configuration-file.md)配置文件中注册ServiceExtensionAbility,type标签需要设置为“enterpriseAdmin”,srcEntry标签表示当前ExtensionAbility组件所对应的代码路径。
```ts ```json
"extensionAbilities": [ "extensionAbilities": [
{ {
"name": "ohos.samples.enterprise_admin_ext_ability", "name": "ohos.samples.enterprise_admin_ext_ability",
...@@ -77,30 +76,35 @@ export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbil ...@@ -77,30 +76,35 @@ export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbil
通过@ohos.enterprise.adminManager模块中的subscribeManagedEvent接口进行企业设备管理事件的订阅,订阅应用安装、卸载事件。当订阅成功后,端侧应用安装和卸载事件通知MDM应用,MDM应用可以在回调函数中进行事件上报,通知企业管理员。并可以通过unsubscribeManagedEvent接口进行企业设备管理事件的去订阅。 通过@ohos.enterprise.adminManager模块中的subscribeManagedEvent接口进行企业设备管理事件的订阅,订阅应用安装、卸载事件。当订阅成功后,端侧应用安装和卸载事件通知MDM应用,MDM应用可以在回调函数中进行事件上报,通知企业管理员。并可以通过unsubscribeManagedEvent接口进行企业设备管理事件的去订阅。
```ts ```ts
@State subscribeManagedEventMsg: string = "" async function subscribeManagedEventCallback() {
@State unsubscribeManagedEventMsg: string = "" let admin: Want = {
bundleName: 'com.example.myapplication',
async subscribeManagedEventCallback() { abilityName: 'EntryAbility',
await adminManager.subscribeManagedEvent(this.admin, }
adminManager.subscribeManagedEvent(admin,
[adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED,
adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED], (error) => { adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED], (error) => {
if (error) { if (error) {
this.subscribeManagedEventMsg = 'subscribeManagedEvent Callback::errorCode: ' + error.code + ' errorMessage: ' + error.message console.error(`Failed to subscribe managed event. Code: ${error.code}, message: ${error.message}`);
} else { } else {
this.subscribeManagedEventMsg = 'subscribeManagedEvent Callback::success' console.log('Succeeded in subscribing managed event');
} }
}) })
} }
async unsubscribeManagedEventPromise() { async function unsubscribeManagedEventPromise() {
await adminManager.unsubscribeManagedEvent(this.admin, let admin: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
}
await adminManager.unsubscribeManagedEvent(admin,
[adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED,
adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED]).then(() => { adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED]).then(() => {
this.unsubscribeManagedEventMsg = 'unsubscribeManagedEvent Promise::success' console.log('Succeeded in subscribing managed event');
}).catch((error) => { }).catch((error: BusinessError) => {
this.unsubscribeManagedEventMsg = 'unsubscribeManagedEvent Promise::errorCode: ' + error.code + ' errorMessage: ' + error.message console.error(`Failed to subscribe managed event. Code: ${error.code}, message: ${error.message}`);
}) })
} }
``` ```
## 相关实例 ## 相关实例
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册