Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
6865f3d4
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
6865f3d4
编写于
8月 30, 2023
作者:
O
openharmony_ci
提交者:
Gitee
8月 30, 2023
浏览文件
操作
浏览文件
下载
差异文件
!23501 【EDM】ArkTS编码规范整改
Merge pull request !23501 from 李兀立/master
上级
d70f2f1e
65ada243
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
41 addition
and
37 deletion
+41
-37
zh-cn/application-dev/application-models/enterprise-extensionAbility.md
...ion-dev/application-models/enterprise-extensionAbility.md
+41
-37
未找到文件。
zh-cn/application-dev/application-models/enterprise-extensionAbility.md
浏览文件 @
6865f3d4
...
...
@@ -40,28 +40,27 @@ onBundleRemoved: 企业应用管理场景下,企业管理员订阅应用卸载
import
EnterpriseAdminExtensionAbility
from
'
@ohos.enterprise.EnterpriseAdminExtensionAbility
'
;
export
default
class
EnterpriseAdminAbility
extends
EnterpriseAdminExtensionAbility
{
onAdminEnabled
()
{
console
.
info
(
"
onAdminEnabled
"
);
}
onAdminEnabled
()
{
console
.
info
(
"
onAdminEnabled
"
);
}
onAdminDisabled
()
{
console
.
info
(
"
onAdminDisabled
"
);
}
onBundleAdded
(
bundleName
:
string
)
{
console
.
info
(
"
EnterpriseAdminAbility onBundleAdded bundleName:
"
+
bundleName
)
}
onBundleRemoved
(
bundleName
:
string
)
{
console
.
info
(
"
EnterpriseAdminAbility onBundleRemoved bundleName
"
+
bundleName
)
}
onAdminDisabled
()
{
console
.
info
(
"
onAdminDisabled
"
);
}
onBundleAdded
(
bundleName
:
string
)
{
console
.
info
(
"
EnterpriseAdminAbility onBundleAdded bundleName:
"
+
bundleName
);
}
onBundleRemoved
(
bundleName
:
string
)
{
console
.
info
(
"
EnterpriseAdminAbility onBundleRemoved bundleName
"
+
bundleName
);
}
};
```
4.在工程Module对应的
[
module.json5
](
../quick-start/module-configuration-file.md
)
配置文件中注册ServiceExtensionAbility,type标签需要设置为“enterpriseAdmin”,srcEntry标签表示当前ExtensionAbility组件所对应的代码路径。
```
ts
```
json
"extensionAbilities"
:
[
{
"name"
:
"ohos.samples.enterprise_admin_ext_ability"
,
...
...
@@ -77,30 +76,35 @@ export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbil
通过@ohos.enterprise.adminManager模块中的subscribeManagedEvent接口进行企业设备管理事件的订阅,订阅应用安装、卸载事件。当订阅成功后,端侧应用安装和卸载事件通知MDM应用,MDM应用可以在回调函数中进行事件上报,通知企业管理员。并可以通过unsubscribeManagedEvent接口进行企业设备管理事件的去订阅。
```
ts
@
State
subscribeManagedEventMsg
:
string
=
""
@
State
unsubscribeManagedEventMsg
:
string
=
""
async
subscribeManagedEventCallback
()
{
await
adminManager
.
subscribeManagedEvent
(
this
.
admin
,
[
adminManager
.
ManagedEvent
.
MANAGED_EVENT_BUNDLE_ADDED
,
adminManager
.
ManagedEvent
.
MANAGED_EVENT_BUNDLE_REMOVED
],
(
error
)
=>
{
if
(
error
)
{
this
.
subscribeManagedEventMsg
=
'
subscribeManagedEvent Callback::errorCode:
'
+
error
.
code
+
'
errorMessage:
'
+
error
.
message
}
else
{
this
.
subscribeManagedEventMsg
=
'
subscribeManagedEvent Callback::success
'
}
})
async
function
subscribeManagedEventCallback
()
{
let
admin
:
Want
=
{
bundleName
:
'
com.example.myapplication
'
,
abilityName
:
'
EntryAbility
'
,
}
async
unsubscribeManagedEventPromise
()
{
a
wait
adminManager
.
unsubscribeManagedEvent
(
this
.
admin
,
[
adminManager
.
ManagedEvent
.
MANAGED_EVENT_BUNDLE_ADDED
,
adminManager
.
ManagedEvent
.
MANAGED_EVENT_BUNDLE_REMOVED
]).
then
(()
=>
{
this
.
unsubscribeManagedEventMsg
=
'
unsubscribeManagedEvent Promise::success
'
}).
catch
((
error
)
=>
{
this
.
unsubscribeManagedEventMsg
=
'
unsubscribeManagedEvent Promise::errorCode:
'
+
error
.
code
+
'
errorMessage:
'
+
error
.
message
adminManager
.
subscribeManagedEvent
(
admin
,
[
adminManager
.
ManagedEvent
.
MANAGED_EVENT_BUNDLE_ADDED
,
a
dminManager
.
ManagedEvent
.
MANAGED_EVENT_BUNDLE_REMOVED
],
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to subscribe managed event. Code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
}
else
{
console
.
log
(
'
Succeeded in subscribing managed event
'
);
}
})
}
async
function
unsubscribeManagedEventPromise
()
{
let
admin
:
Want
=
{
bundleName
:
'
com.example.myapplication
'
,
abilityName
:
'
EntryAbility
'
,
}
await
adminManager
.
unsubscribeManagedEvent
(
admin
,
[
adminManager
.
ManagedEvent
.
MANAGED_EVENT_BUNDLE_ADDED
,
adminManager
.
ManagedEvent
.
MANAGED_EVENT_BUNDLE_REMOVED
]).
then
(()
=>
{
console
.
log
(
'
Succeeded in subscribing managed event
'
);
}).
catch
((
error
:
BusinessError
)
=>
{
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录