Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
6a8b2abd
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看板
提交
6a8b2abd
编写于
1月 19, 2023
作者:
Z
zhutianyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改
Signed-off-by:
N
zhutianyi
<
zhutianyi2@huawei.com
>
上级
8ae51d4a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
28 addition
and
28 deletion
+28
-28
zh-cn/application-dev/task-management/workscheduler-extensionability.md
...ion-dev/task-management/workscheduler-extensionability.md
+28
-28
未找到文件。
zh-cn/application-dev/task-management/workscheduler-extensionability.md
浏览文件 @
6a8b2abd
...
...
@@ -43,7 +43,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
导入模块。
```
ts
import
WorkSchedulerExtensionAbility
from
'
@ohos.WorkSchedulerExtensionAbility
'
import
WorkSchedulerExtensionAbility
from
'
@ohos.WorkSchedulerExtensionAbility
'
;
```
实现WorkSchedulerExtension生命周期接口。
...
...
@@ -52,27 +52,27 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
export
default
class
workAbility
extends
WorkSchedulerExtensionAbility
{
// 延迟任务开始回调
onWorkStart
(
workInfo
)
{
console
.
log
(
`onWorkStart CommonEvent publish start
${
JSON
.
stringify
(
workInfo
)}
`
)
console
.
log
(
`onWorkStart CommonEvent publish start
${
JSON
.
stringify
(
workInfo
)}
`
)
;
// 发送升级通知
let
notificationRequest
=
notification
.
getNotificationContentBasic
(
'
upgrade
'
,
upgradeMessage
,
''
)
let
notificationRequest
=
notification
.
getNotificationContentBasic
(
'
upgrade
'
,
upgradeMessage
,
''
)
;
notification
.
publish
(
notificationRequest
,
(
err
)
=>
{
if
(
err
)
{
console
.
log
(
`onWorkStart notification publish err
${
JSON
.
stringify
(
err
)}
`
)
console
.
log
(
`onWorkStart notification publish err
${
JSON
.
stringify
(
err
)}
`
)
;
}
console
.
log
(
`onWorkStart notification publish success`
)
})
console
.
log
(
`onWorkStart notification publish success`
)
;
})
;
}
// 延迟任务结束回调
onWorkStop
(
workInfo
)
{
// 发送升级完成通知
let
notificationRequest
=
notification
.
getNotificationContentBasic
(
'
upgrade
'
,
'
upgrade success
'
,
''
)
let
notificationRequest
=
notification
.
getNotificationContentBasic
(
'
upgrade
'
,
'
upgrade success
'
,
''
)
;
notification
.
publish
(
notificationRequest
,
(
err
)
=>
{
if
(
err
)
{
console
.
log
(
`onWorkStop notification publish err
${
JSON
.
stringify
(
err
)}
`
)
console
.
log
(
`onWorkStop notification publish err
${
JSON
.
stringify
(
err
)}
`
)
;
}
console
.
log
(
`onWorkStop notification publish success`
)
})
console
.
log
(
`onWorkStop notification publish success`
)
;
})
;
}
}
```
...
...
@@ -83,7 +83,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
导入模块。
```
ts
import
{
workAbility
}
from
'
@ohos/library
'
import
{
workAbility
}
from
'
@ohos/library
'
;
```
继承workAbility,实现WorkSchedulerExtension生命周期接口。
...
...
@@ -91,13 +91,13 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
```
ts
export
default
class
WorkTest
extends
workAbility
{
onWorkStart
(
workInfo
)
{
console
.
log
(
`onWorkStartTest start
${
JSON
.
stringify
(
workInfo
)}
`
)
super
.
onWorkStart
(
workInfo
)
console
.
log
(
`onWorkStartTest start
${
JSON
.
stringify
(
workInfo
)}
`
)
;
super
.
onWorkStart
(
workInfo
)
;
}
onWorkStopTest
(
workInfo
)
{
super
.
onWorkStop
(
workInfo
)
console
.
log
(
`onWorkStop value`
)
super
.
onWorkStop
(
workInfo
)
;
console
.
log
(
`onWorkStop value`
)
;
}
}
```
...
...
@@ -109,7 +109,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
导入模块。
```
ts
import
workScheduler
from
'
@ohos.resourceschedule.workScheduler
'
import
workScheduler
from
'
@ohos.resourceschedule.workScheduler
'
;
```
封装延迟任务注册、停止接口。
...
...
@@ -124,13 +124,13 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
}
// 注册延迟任务
startWork
(
bundleName
:
string
,
abilityName
:
string
)
{
this
.
workInfo
.
bundleName
=
bundleName
this
.
workInfo
.
abilityName
=
abilityName
this
.
workInfo
.
bundleName
=
bundleName
;
this
.
workInfo
.
abilityName
=
abilityName
;
try
{
workScheduler
.
startWork
(
this
.
workInfo
)
console
.
log
(
`startWork success`
)
workScheduler
.
startWork
(
this
.
workInfo
)
;
console
.
log
(
`startWork success`
)
;
}
catch
(
error
)
{
Logger
.
error
(
TAG
,
`startWork startwork failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
)
Logger
.
error
(
TAG
,
`startWork startwork failed. code is
${
error
.
code
}
message is
${
error
.
message
}
`
)
;
prompt
.
showToast
({
message
:
`
${
error
.
message
}
`
})
...
...
@@ -139,10 +139,10 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
// 停止延迟任务
stopWork
(
bundleName
:
string
,
abilityName
:
string
)
{
this
.
workInfo
.
bundleName
=
bundleName
this
.
workInfo
.
abilityName
=
abilityName
workScheduler
.
stopWork
(
this
.
workInfo
,
false
)
console
.
log
(
`stopWork`
)
this
.
workInfo
.
bundleName
=
bundleName
;
this
.
workInfo
.
abilityName
=
abilityName
;
workScheduler
.
stopWork
(
this
.
workInfo
,
false
)
;
console
.
log
(
`stopWork`
)
;
}
}
```
...
...
@@ -152,7 +152,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
导入模块。
```
ts
import
{
workAbility
}
from
'
@ohos/library
'
import
{
workAbility
}
from
'
@ohos/library
'
;
```
增加“升级”按钮,调用library封装的延迟任务注册接口,传入bundleName和abilityName,其中bilityName为WorkTest。
...
...
@@ -163,7 +163,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
.
height
(
40
)
.
fontSize
(
30
)
.
onClick
(()
=>
{
this
.
work
.
startWork
(
'
ohos.samples.workscheduler
'
,
'
WorkTest
'
)
this
.
work
.
startWork
(
'
ohos.samples.workscheduler
'
,
'
WorkTest
'
)
;
})
```
...
...
@@ -171,7 +171,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
```
ts
aboutToDisappear
()
{
this
.
work
.
stopWork
(
'
ohos.samples.workscheduler
'
,
'
WorkTest
'
)
this
.
work
.
stopWork
(
'
ohos.samples.workscheduler
'
,
'
WorkTest
'
)
;
}
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录