Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
2a3261ae
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
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看板
提交
2a3261ae
编写于
5月 19, 2023
作者:
zyjhandsome
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
同步Master修改内容到分支
Signed-off-by:
zyjhandsome
<
zyjhandsome@126.com
>
上级
9be46dc9
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
232 addition
and
248 deletion
+232
-248
zh-cn/application-dev/application-models/common-event-overview.md
...plication-dev/application-models/common-event-overview.md
+4
-7
zh-cn/application-dev/application-models/process-model-stage.md
...application-dev/application-models/process-model-stage.md
+8
-7
zh-cn/application-dev/application-models/stage-model-development-overview.md
...ev/application-models/stage-model-development-overview.md
+1
-1
zh-cn/application-dev/application-models/thread-model-stage.md
.../application-dev/application-models/thread-model-stage.md
+10
-9
zh-cn/application-dev/notification/figures/zh-cn_image_0000001466462305.png
...dev/notification/figures/zh-cn_image_0000001466462305.png
+0
-0
zh-cn/application-dev/notification/notification-enable.md
zh-cn/application-dev/notification/notification-enable.md
+6
-6
zh-cn/application-dev/notification/notification-overview.md
zh-cn/application-dev/notification/notification-overview.md
+2
-1
zh-cn/application-dev/notification/notification-subscription.md
...application-dev/notification/notification-subscription.md
+35
-35
zh-cn/application-dev/notification/notification-with-wantagent.md
...plication-dev/notification/notification-with-wantagent.md
+75
-89
zh-cn/application-dev/notification/progress-bar-notification.md
...application-dev/notification/progress-bar-notification.md
+15
-14
zh-cn/application-dev/notification/text-notification.md
zh-cn/application-dev/notification/text-notification.md
+76
-79
未找到文件。
zh-cn/application-dev/application-models/common-event-overview.md
浏览文件 @
2a3261ae
...
@@ -7,18 +7,15 @@ OpenHarmony通过CES(Common Event Service,公共事件服务)为应用程
...
@@ -7,18 +7,15 @@ OpenHarmony通过CES(Common Event Service,公共事件服务)为应用程
公共事件从系统角度可分为:系统公共事件和自定义公共事件。
公共事件从系统角度可分为:系统公共事件和自定义公共事件。
-
系统公共事件:CES内部定义的公共事件,只有系统应用和系统服务才能发布,例如HAP安装,更新,卸载等公共事件。目前支持的系统公共事件详见
[
系统公共事件列表
](
../reference/apis/commonEventManager-definitions.md
)
。
-
系统公共事件:CES内部定义的公共事件,当前仅支持系统应用和系统服务发布,例如HAP安装,更新,卸载等公共事件。目前支持的系统公共事件请参见
[
系统公共事件列表
](
../reference/apis/commonEventManager-definitions.md
)
。
-
自定义公共事件:应用定义的公共事件,可用于实现跨进程的事件通信能力。
-
自定义公共事件:应用自定义一些公共事件用来实现跨进程的事件通信能力。
公共事件按发送方式可分为:无序公共事件、有序公共事件和粘性公共事件。
公共事件按发送方式可分为:无序公共事件、有序公共事件和粘性公共事件。
-
无序公共事件:CES转发公共事件时,不考虑订阅者是否接收到,且订阅者接收到的顺序与其订阅顺序无关。
-
无序公共事件:CES在转发公共事件时,不考虑订阅者是否接收到该事件,也不保证订阅者接收到该事件的顺序与其订阅顺序一致。
-
有序公共事件:CES在转发公共事件时,根据订阅者设置的优先级等级,优先将公共事件发送给优先级较高的订阅者,等待其成功接收该公共事件之后再将事件发送给优先级较低的订阅者。如果有多个订阅者具有相同的优先级,则他们将随机接收到公共事件。
-
有序公共事件:CES转发公共事件时,根据订阅者设置的优先级等级,在接收到优先级较高的一个订阅者回复后,再向下一个优先级较低的订阅者转发公共事件。具有相同优先级的订阅者将按随机顺序收到公共事件。
-
粘性公共事件:能够让订阅者收到在订阅前已经发送的公共事件就是粘性公共事件。普通的公共事件只能在订阅后发送才能收到,而粘性公共事件的特殊性就是可以先发送后订阅,同时也支持先订阅后发送。发送粘性事件必须是系统应用或系统服务,粘性事件发送后会一直存在系统中,且发送者需要申请
`ohos.permission.COMMONEVENT_STICKY`
权限,配置方式请参见
[
配置文件权限声明
](
../security/accesstoken-guidelines.md#配置文件权限声明
)
。
-
粘性公共事件:能够让订阅者收到在订阅前已经发送的公共事件就是粘性公共事件。普通的公共事件只能在订阅后发送才能收到,而粘性公共事件的特殊性就是可以先发送后订阅,同时也支持先订阅后发送。发送粘性事件必须是系统应用或系统服务,粘性事件发送后会一直存在系统中,且发送者需要申请
`ohos.permission.COMMONEVENT_STICKY`
权限,配置方式请参见
[
配置文件权限声明
](
../security/accesstoken-guidelines.md#配置文件权限声明
)
。
...
...
zh-cn/application-dev/application-models/process-model-stage.md
浏览文件 @
2a3261ae
# 进程模型概述
# 进程模型概述
OpenHarmony的进程模型如下图所示
:
OpenHarmony的进程模型如下图所示
。
-
应用中(同一Bundle名称)的所有UIAbility、ServiceExtensionAbility、DataShareExtensionAbility运行在同一个独立进程中,
即
图中绿色部分的“Main Process”。
-
应用中(同一Bundle名称)的所有UIAbility、ServiceExtensionAbility、DataShareExtensionAbility运行在同一个独立进程中,
如下
图中绿色部分的“Main Process”。
-
应用中(同一Bundle名称)的同一类型ExtensionAbility(除ServiceExtensionAbility和DataShareExtensionAbility外)运行在一个独立进程中,
即
图中蓝色部分的“FormExtensionAbility Process”、“InputMethodExtensionAbility Process”、其他ExtensionAbility Process。
-
应用中(同一Bundle名称)的同一类型ExtensionAbility(除ServiceExtensionAbility和DataShareExtensionAbility外)运行在一个独立进程中,
如下
图中蓝色部分的“FormExtensionAbility Process”、“InputMethodExtensionAbility Process”、其他ExtensionAbility Process。
-
WebView拥有独立的渲染进程,
即
图中黄色部分的“Render Process”。
-
WebView拥有独立的渲染进程,
如下
图中黄色部分的“Render Process”。
**图1**
进程模型示意图
**图1**
进程模型示意图


> 说明:
> 说明:
...
@@ -20,7 +21,7 @@ OpenHarmony的进程模型如下图所示:
...
@@ -20,7 +21,7 @@ OpenHarmony的进程模型如下图所示:
在上述模型基础上,对于系统应用可以通过申请多进程权限(如下图所示),为指定HAP配置一个自定义进程名,该HAP中的UIAbility、DataShareExtensionAbility、ServiceExtensionAbility就会运行在自定义进程中。不同的HAP可以通过配置不同的进程名运行在不同进程中。
在上述模型基础上,对于系统应用可以通过申请多进程权限(如下图所示),为指定HAP配置一个自定义进程名,该HAP中的UIAbility、DataShareExtensionAbility、ServiceExtensionAbility就会运行在自定义进程中。不同的HAP可以通过配置不同的进程名运行在不同进程中。
**图2**
多进程示意图
**图2**
多进程示意图


...
@@ -29,4 +30,4 @@ OpenHarmony的进程模型如下图所示:
...
@@ -29,4 +30,4 @@ OpenHarmony的进程模型如下图所示:
-
[
公共事件机制
](
common-event-overview.md
)
:多用于一对多的通信场景,公共事件发布者可能存在多个订阅者同时接收事件。
-
[
公共事件机制
](
common-event-overview.md
)
:多用于一对多的通信场景,公共事件发布者可能存在多个订阅者同时接收事件。
-
[
后台服务机制
](
background-services.md
)
:
当前主要
通过
[
ServiceExtensionAbility
](
serviceextensionability.md
)
的能力实现。
-
[
后台服务机制
](
background-services.md
)
:通过
[
ServiceExtensionAbility
](
serviceextensionability.md
)
的能力实现。
zh-cn/application-dev/application-models/stage-model-development-overview.md
浏览文件 @
2a3261ae
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
-
ExtensionAbility组件是一种面向特定场景的应用组件。开发者并不直接从ExtensionAbility派生,而是需要使用ExtensionAbility的派生类。目前ExtensionAbility有用于卡片场景的FormExtensionAbility,用于输入法场景的InputMethodExtensionAbility,用于闲时任务场景的WorkSchedulerExtensionAbility等多种派生类,这些派生类都是基于特定场景提供的。例如,用户在桌面创建应用的卡片,需要应用开发者从FormExtensionAbility派生,实现其中的回调函数,并在配置文件中配置该能力。ExtensionAbility派生类实例由用户触发创建,并由系统管理生命周期。在Stage模型上,普通应用开发者不能开发自定义服务,而需要根据自身的业务场景通过ExtensionAbility的派生类来实现。
-
ExtensionAbility组件是一种面向特定场景的应用组件。开发者并不直接从ExtensionAbility派生,而是需要使用ExtensionAbility的派生类。目前ExtensionAbility有用于卡片场景的FormExtensionAbility,用于输入法场景的InputMethodExtensionAbility,用于闲时任务场景的WorkSchedulerExtensionAbility等多种派生类,这些派生类都是基于特定场景提供的。例如,用户在桌面创建应用的卡片,需要应用开发者从FormExtensionAbility派生,实现其中的回调函数,并在配置文件中配置该能力。ExtensionAbility派生类实例由用户触发创建,并由系统管理生命周期。在Stage模型上,普通应用开发者不能开发自定义服务,而需要根据自身的业务场景通过ExtensionAbility的派生类来实现。
-
[
WindowStage
](
../windowmanager/application-window-stage.md
)
-
[
WindowStage
](
../windowmanager/application-window-stage.md
)
每个UIAbility类实例都会与一个WindowStage类实例绑定,该类提供了应用进程内窗口管理器的作用。它包含一个主窗口
(Window)
。也就是说UIAbility通过WindowStage持有了一个主窗口,该主窗口为ArkUI提供了绘制区域。
每个UIAbility类实例都会与一个WindowStage类实例绑定,该类提供了应用进程内窗口管理器的作用。它包含一个主窗口。也就是说UIAbility通过WindowStage持有了一个主窗口,该主窗口为ArkUI提供了绘制区域。
-
[
Context
](
application-context-stage.md
)
-
[
Context
](
application-context-stage.md
)
...
...
zh-cn/application-dev/application-models/thread-model-stage.md
浏览文件 @
2a3261ae
...
@@ -2,19 +2,20 @@
...
@@ -2,19 +2,20 @@
在OpenHarmony应用中,每个进程都会有一个主线程,主线程具有以下职责:
在OpenHarmony应用中,每个进程都会有一个主线程,主线程具有以下职责:
1.
执行UI绘制
;
1.
执行UI绘制
。
2.
管理主线程的ArkTS引擎实例,使多个UIAbility组件能够运行在其之上
;
2.
管理主线程的ArkTS引擎实例,使多个UIAbility组件能够运行在其之上
。
3.
管理其他线程(例如Worker线程)的ArkTS引擎实例,例如启动和终止其他线程
;
3.
管理其他线程(例如Worker线程)的ArkTS引擎实例,例如启动和终止其他线程
。
4.
分发交互事件
;
4.
分发交互事件
。
5.
处理应用代码的回调,包括事件处理和生命周期管理
;
5.
处理应用代码的回调,包括事件处理和生命周期管理
。
6.
接收Worker线程发送的消息
;
6.
接收Worker线程发送的消息
。
除了主线程外,还有一类独立的Worker线程,用于执行耗时操作。Worker线程在主线程中创建,与主线程相互独立,但不能直接操作UI。最多可以创建7个Worker线程。
除了主线程外,还有一类独立的Worker线程,用于执行耗时操作。Worker线程在主线程中创建,与主线程相互独立,但不能直接操作UI。最多可以创建7个Worker线程。


基于OpenHarmony的线程模型,不同的业务功能运行在不同的线程上,业务功能的交互就需要线程间通信。同一个进程内,线程间通信目前主要有Emitter和Worker两种方式,其中Emitter主要适用于线程间的事件同步,
Worker主要用于新开一个线程执行耗时任务。
基于OpenHarmony的线程模型,不同的业务功能运行在不同的线程上,业务功能的交互就需要线程间通信。同一个进程内,线程间通信目前主要有Emitter和Worker两种方式,其中Emitter主要适用于线程间的事件同步,Worker主要用于新开一个线程执行耗时任务。
> **说明:**
> **说明:**
>
>
> - Stage模型只提供了主线程和Worker线程,Emitter主要用于主线程内或者主线程和Worker线程的事件同步。
> - Stage模型只提供了主线程和Worker线程,Emitter主要用于主线程和Worker线程、Worker线程和Worker线程之间的事件同步。
> - 执行`hdc shell`命令,进入设备的shell命令行。在shell命令行中,执行`ps -p <pid> -T`命令,可以查看指定应用进程的线程信息。其中,`<pid>`为需要指定的应用进程的进程ID。
> - UIAbility组件与UI均在主线程中,他们之间的数据同步请参见[UIAbility组件与UI的数据同步](uiability-data-sync-with-ui.md)。
> - 执行`hdc shell`命令,进入设备的shell命令行。在shell命令行中,执行`ps -p <pid> -T`命令,可以查看指定应用进程的线程信息。其中,`<pid>`为需要指定的应用进程的[进程ID](process-model-stage.md)。
zh-cn/application-dev/notification/figures/zh-cn_image_0000001466462305.png
查看替换文件 @
9be46dc9
浏览文件 @
2a3261ae
408.6 KB
|
W:
|
H:
366.8 KB
|
W:
|
H:
2-up
Swipe
Onion skin
zh-cn/application-dev/notification/notification-enable.md
浏览文件 @
2a3261ae
# 使能通知开关
# 使能通知开关
应用需要开启通知开关才能发送通知。开发者可以在通知发布前调用
[
requestEnableNotification()
](
../reference/apis/js-apis-notificationManager.md#notificationrequestenablenotification
)
方法,弹窗让用户选择是否开启使能开关,仅弹窗一次,后续调用该接口不再弹窗。
应用需要开启通知开关才能发送通知。开发者可以在通知发布前调用
[
requestEnableNotification()
](
../reference/apis/js-apis-notificationManager.md#notification
manager
requestenablenotification
)
方法,弹窗让用户选择是否开启使能开关,仅弹窗一次,后续调用该接口不再弹窗。
**图1**
使能通知开关示意图
**图1**
使能通知开关示意图


-
点击“允许”后,则表示允许应用发送通知。
-
点击“允许”后,则表示允许应用发送通知。
-
点击“取消”后,再次调用
[
requestEnableNotification()
](
../reference/apis/js-apis-notificationManager.md#notificationrequestenablenotification
)
方法,则不再弹窗。此时如需要手动使能通知开关,操作步骤如下所示。
-
点击“取消”后,再次调用
[
requestEnableNotification()
](
../reference/apis/js-apis-notificationManager.md#notification
manager
requestenablenotification
)
方法,则不再弹窗。此时如需要手动使能通知开关,操作步骤如下所示。
| ①从设备左上方下拉,进入通知界面 | ②点击右上角“设置”图标,进入通知界面,找到需要打开通知开关的应用 | ③打开“允许通知”开关 |
| ①从设备左上方下拉,进入通知界面 | ②点击右上角“设置”图标,进入通知界面,找到需要打开通知开关的应用 | ③打开“允许通知”开关 |
| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
...
@@ -34,16 +34,16 @@
...
@@ -34,16 +34,16 @@
1.
导入NotificationManager模块。
1.
导入NotificationManager模块。
```
ts
```
ts
import
N
otificationManager
from
'
@ohos.notificationManager
'
;
import
n
otificationManager
from
'
@ohos.notificationManager
'
;
```
```
2.
请求发送通知的许可。
2.
请求发送通知的许可。
```
ts
```
ts
N
otificationManager
.
requestEnableNotification
().
then
(()
=>
{
n
otificationManager
.
requestEnableNotification
().
then
(()
=>
{
console
.
info
(
`[ANS] requestEnableNotification success`
);
console
.
info
(
`[ANS] requestEnableNotification success`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
`[ANS] requestEnableNotification failed,
errCode[
${
err
}
]
`
);
console
.
error
(
`[ANS] requestEnableNotification failed,
code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
});
```
```
zh-cn/application-dev/notification/notification-overview.md
浏览文件 @
2a3261ae
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
-
显示当前正在进行的事件,如下载等。
-
显示当前正在进行的事件,如下载等。
OpenHarmony通过ANS(Advanced Notification Service,通知系统服务)对通知类型的消息进行管理,支持多种通知类型,如基础类型通知、进度条类型通知、后台代理提醒。
OpenHarmony通过ANS(Advanced Notification Service,通知系统服务)对通知类型的消息进行管理,支持多种通知类型,
例
如基础类型通知、进度条类型通知、后台代理提醒。
## 通知业务流程
## 通知业务流程
...
@@ -24,6 +24,7 @@ OpenHarmony通过ANS(Advanced Notification Service,通知系统服务)对
...
@@ -24,6 +24,7 @@ OpenHarmony通过ANS(Advanced Notification Service,通知系统服务)对
系统应用还支持通知相关配置,如使能开关、配置参数由系统配置发起请求,发送到通知子系统存储到内存和数据库。
系统应用还支持通知相关配置,如使能开关、配置参数由系统配置发起请求,发送到通知子系统存储到内存和数据库。
**图1**
通知业务流程


## 相关实例
## 相关实例
...
...
zh-cn/application-dev/notification/notification-subscription.md
浏览文件 @
2a3261ae
...
@@ -20,64 +20,64 @@
...
@@ -20,64 +20,64 @@
**表2**
通知订阅回调接口介绍
**表2**
通知订阅回调接口介绍
| | |
| -------- | -------- |
|
**接口名**
|
**描述**
|
|
**接口名**
|
**描述**
|
| onConsume?:(data:
SubscribeCallbackData)
=
>
void | 通知回调。 |
| -------- | -------- |
| onCancel?:(data:
SubscribeCallbackData)
=
>
void | 通知取消回调。 |
| onConsume?:(data:
SubscribeCallbackData)
=
>
void | 通知回调。 |
| onUpdate?:(data:
NotificationSortingMap)
=
>
void | 通知排序更新回调。 |
| onCancel?:(data:
SubscribeCallbackData)
=
>
void | 通知取消回调。 |
| onConnect?:()
=
>
void; | 订阅成功回调。 |
| onUpdate?:(data:
NotificationSortingMap)
=
>
void | 通知排序更新回调。 |
| onDisconnect?:()
=
>
void; | 取消订阅回调。 |
| onConnect?:()
=
>
void; | 订阅成功回调。 |
| onDestroy?:()
=
>
void | 与通知子系统断开回调。 |
| onDisconnect?:()
=
>
void; | 取消订阅回调。 |
| onDestroy?:()
=
>
void | 与通知子系统断开回调。 |
| onDoNotDisturbDateChange?:(mode:
notification.DoNotDisturbDate)
=
>
void | 免打扰时间选项变更回调。 |
| onDoNotDisturbDateChange?:(mode:
notification.DoNotDisturbDate)
=
>
void | 免打扰时间选项变更回调。 |
| onEnabledNotificationChanged?:(callbackData:
EnabledNotificationCallbackData)
=
>
void | 通知开关变更回调。 |
| onEnabledNotificationChanged?:(callbackData:
EnabledNotificationCallbackData)
=
>
void | 通知开关变更回调。
|
## 开发步骤
## 开发步骤
1.
申请
`ohos.permission.NOTIFICATION_CONTROLLER`
权限,配置方式请参
阅
[
访问控制授权申请指导
](
../security/accesstoken-guidelines.md
)
。
1.
申请
`ohos.permission.NOTIFICATION_CONTROLLER`
权限,配置方式请参
见
[
访问控制授权申请
](
../security/accesstoken-guidelines.md#配置文件权限声明
)
。
2.
导入通知订阅模块。
2.
导入通知订阅模块。
```
ts
```
ts
import
N
otificationSubscribe
from
'
@ohos.notificationSubscribe
'
;
import
n
otificationSubscribe
from
'
@ohos.notificationSubscribe
'
;
```
```
3.
创建订阅者对象。
3.
创建订阅者对象。
```
ts
```
ts
let
subscriber
=
{
let
subscriber
=
{
onConsume
:
function
(
data
)
{
onConsume
:
function
(
data
)
{
let
req
=
data
.
request
;
let
req
=
data
.
request
;
console
.
info
(
'
[ANS] onConsume callback req.id:
'
+
req
.
id
);
console
.
info
(
`onConsume callback. req.id:
${
req
.
id
}
`
);
},
},
onCancel
:
function
(
data
)
{
onCancel
:
function
(
data
)
{
let
req
=
data
.
request
;
let
req
=
data
.
request
;
console
.
info
(
'
[ANS] onCancel callback req.id: :
'
+
req
.
id
);
console
.
info
(
`onCancel callback. req.id:
${
req
.
id
}
`
);
},
},
onUpdate
:
function
(
data
)
{
onUpdate
:
function
(
data
)
{
console
.
info
(
'
[ANS] onUpdate in test
'
);
let
req
=
data
.
request
;
},
console
.
info
(
`onUpdate callback. req.id:
${
req
.
id
}
`
);
onConnect
:
function
()
{
},
console
.
info
(
'
[ANS] onConnect in test
'
);
onConnect
:
function
()
{
},
console
.
info
(
`onConnect callback.}`
);
onDisconnect
:
function
()
{
},
console
.
info
(
'
[ANS] onDisConnect in test
'
);
onDisconnect
:
function
()
{
},
console
.
info
(
`onDisconnect callback.}`
);
onDestroy
:
function
()
{
},
console
.
info
(
'
[ANS] onDestroy in test
'
);
onDestroy
:
function
()
{
},
console
.
info
(
`onDestroy callback.}`
);
},
};
};
```
```
4.
发起通知订阅。
4.
发起通知订阅。
```
ts
```
ts
N
otificationSubscribe
.
subscribe
(
subscriber
,
(
err
,
data
)
=>
{
// callback形式调用异步接口
n
otificationSubscribe
.
subscribe
(
subscriber
,
(
err
,
data
)
=>
{
// callback形式调用异步接口
if
(
err
)
{
if
(
err
)
{
console
.
error
(
`
[ANS] failed to subscribe, error[
${
err
}
]
`
);
console
.
error
(
`
Failed to subscribe notification. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
return
;
}
}
console
.
info
(
`
[ANS] subscribeTest success : +
${
data
}
`
);
console
.
info
(
`
Succeeded in subscribing to notification. Data:
${
data
}
`
);
});
});
```
```
zh-cn/application-dev/notification/notification-with-wantagent.md
浏览文件 @
2a3261ae
# 为通知添加行为意图
# 为通知添加行为意图
[
WantAgent
](
../reference/apis/js-apis-app-ability-wantAgent.md
)
提供了封装行为意图的能力,该行为意图是指拉起指定的应用组件及发布公共事件等能力。OpenHarmony支持以通知的形式,将
[
WantAgent
](
../reference/apis/js-apis-app-ability-wantAgent.md
)
从发布方传递至接收方,从而在接收方触发
[
WantAgent
](
../reference/apis/js-apis-app-ability-wantAgent.md
)
中指定的意图。例如在通知消息的发布者发布通知时,通常期望用户可以通过通知栏点击拉起目标应用组件。为了达成这一目标,开发者可以将
[
WantAgent
](
../reference/apis/js-apis-app-ability-wantAgent.md
)
封装至通知消息中,当系统接收到
[
WantAgent
](
../reference/apis/js-apis-app-ability-wantAgent.md
)
后,在用户点击通知栏时触发
[
WantAgent
](
../reference/apis/js-apis-app-ability-wantAgent.md
)
的意图,从而拉起目标应用组件。
WantAgent提供了封装行为意图的能力,这里所说的行为意图主要是指拉起指定的应用组件及发布公共事件等能力。OpenHarmony支持以通知的形式,将WantAgent从发布方传递至接收方,从而在接收方触发WantAgent中指定的意图。例如,在通知消息的发布者发布通知时,通常期望用户可以通过通知栏点击拉起目标应用组件。为了达成这一目标,开发者可以将WantAgent封装至通知消息中,当系统接收到WantAgent后,在用户点击通知栏时触发WantAgent的意图,从而拉起目标应用组件
。
为通知添加行为意图的实现方式如下图所示:发布通知的应用向应用组件管理服务AMS(Ability Manager Service)申请
[
WantAgent
](
../reference/apis/js-apis-app-ability-wantAgent.md
)
,然后随其他通知信息一起发送给桌面,当用户在桌面通知栏上点击通知时,触发
[
WantAgent
](
../reference/apis/js-apis-app-ability-wantAgent.md
)
动作
。
**图1**
携带行为意图的通知运行机制
为通知添加行为意图的实现方式如下图所示:发布通知的应用向应用组件管理服务AMS(Ability Manager Service)申请WantAgent,然后随其他通知信息一起发送给桌面,当用户在桌面通知栏上点击通知时,触发WantAgent动作。
**图1**
携带行为意图的通知运行机制


## 接口说明
## 接口说明
具体接口描述,详见
[
WantAgent接口文档
](
../reference/apis/js-apis-wantAgent.md
)
。
具体接口描述,详见
[
WantAgent接口文档
](
../reference/apis/js-apis-
app-ability-
wantAgent.md
)
。
|
**接口名**
|
**描述**
|
|
**接口名**
|
**描述**
|
| -------- | -------- |
| -------- | -------- |
...
@@ -25,111 +23,99 @@ WantAgent提供了封装行为意图的能力,这里所说的行为意图主
...
@@ -25,111 +23,99 @@ WantAgent提供了封装行为意图的能力,这里所说的行为意图主
## 开发步骤
## 开发步骤
1.
导入模块。
1.
[
使能通知开关
](
notification-enable.md
)
,获得用户授权后,才能使用通知功能。
```
ts
2.
导入模块。
import
NotificationManager
from
'
@ohos.notificationManager
'
;
```
typescript
import
notificationManager
from
'
@ohos.notificationManager
'
;
import
wantAgent
from
'
@ohos.app.ability.wantAgent
'
;
import
wantAgent
from
'
@ohos.app.ability.wantAgent
'
;
```
```
2.
创建WantAgentInfo信息。
3.
创建WantAgentInfo信息。
场景一:创建拉起Ability的WantAgent的
[
WantAgentInfo
](
../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md
)
信息。
场景一:创建拉起UIAbility的WantAgent的
[
WantAgentInfo
](
../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md
)
信息。
```
ts
```
typescript
let
wantAgentObj
=
null
;
// 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。
let
wantAgentObj
=
null
;
// 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。
// 通过WantAgentInfo的operationType设置动作类型
。
// 通过WantAgentInfo的operationType设置动作类型
let
wantAgentInfo
=
{
let
wantAgentInfo
=
{
wants
:
[
wants
:
[
{
{
deviceId
:
''
,
deviceId
:
''
,
bundleName
:
'
com.example.test
'
,
bundleName
:
'
com.example.myapplication
'
,
abilityName
:
'
com.example.test.Main
Ability
'
,
abilityName
:
'
Entry
Ability
'
,
action
:
''
,
action
:
''
,
entities
:
[],
entities
:
[],
uri
:
''
,
uri
:
''
,
parameters
:
{}
parameters
:
{}
}
}
],
],
operationType
:
wantAgent
.
OperationType
.
START_ABILITY
,
operationType
:
wantAgent
.
OperationType
.
START_ABILITY
,
requestCode
:
0
,
requestCode
:
0
,
wantAgentFlags
:[
wantAgent
.
WantAgentFlags
.
CONSTANT_FLAG
]
wantAgentFlags
:[
wantAgent
.
WantAgentFlags
.
CONSTANT_FLAG
]
}
}
;
```
```
场景二:创建发布公共事件
的WantAgent的[WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md)信息。
场景二:创建发布
[
公共事件
](
../application-models/common-event-overview.md
)
的WantAgent的
[
WantAgentInfo
](
../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md
)
信息。
```
t
s
```
t
ypescript
let
wantAgentObj
=
null
;
// 用于保存创建成功的WantAgent对象,后续使用其完成触发的动作。
let
wantAgentObj
=
null
;
// 用于保存创建成功的WantAgent对象,后续使用其完成触发的动作。
//
wantAgentInfo
//
通过WantAgentInfo的operationType设置动作类型
let
wantAgentInfo
=
{
let
wantAgentInfo
=
{
wants
:
[
wants
:
[
{
{
action
:
'
event_name
'
,
// 设置事件名。
action
:
'
event_name
'
,
// 设置事件名
parameters
:
{},
parameters
:
{},
}
}
],
],
operationType
:
wantAgent
.
OperationType
.
SEND_COMMON_EVENT
,
operationType
:
wantAgent
.
OperationType
.
SEND_COMMON_EVENT
,
requestCode
:
0
,
requestCode
:
0
,
wantAgentFlags
:
[
wantAgent
.
WantAgentFlags
.
CONSTANT_FLAG
],
wantAgentFlags
:
[
wantAgent
.
WantAgentFlags
.
CONSTANT_FLAG
],
}
}
;
```
```
3.
创建WantAgent。
4.
调用
[
getWantAgent()
](
../reference/apis/js-apis-app-ability-wantAgent.md#wantagentgetwantagent
)
方法进行
创建WantAgent。
```
t
s
```
t
ypescript
// 创建WantAgent
// 创建WantAgent
wantAgent
.
getWantAgent
(
wantAgentInfo
,
(
err
,
data
)
=>
{
wantAgent
.
getWantAgent
(
wantAgentInfo
,
(
err
,
data
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
[WantAgent]getWantAgent err=
'
+
JSON
.
stringify
(
err
)
);
console
.
error
(
`Failed to get want agent. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
return
;
console
.
info
(
'
[WantAgent]getWantAgent success
'
);
}
wantAgentObj
=
data
;
console
.
info
(
'
Succeeded in geting want agent.
'
)
;
}
wantAgentObj
=
data
;
});
});
```
```
4.
构造NotificationRequest对象
。
5.
构造NotificationRequest对象,并发布WantAgent通知
。
```
t
s
```
t
ypescript
// 构造NotificationRequest对象
// 构造NotificationRequest对象
let
notificationRequest
=
{
let
notificationRequest
:
notificationManager
.
NotificationRequest
=
{
content
:
{
content
:
{
contentType
:
NotificationManager
.
ContentType
.
NOTIFICATION_CONTENT_BASIC_TEXT
,
contentType
:
notificationManager
.
ContentType
.
NOTIFICATION_CONTENT_BASIC_TEXT
,
normal
:
{
normal
:
{
title
:
'
Test_Title
'
,
title
:
'
Test_Title
'
,
text
:
'
Test_Text
'
,
text
:
'
Test_Text
'
,
additionalText
:
'
Test_AdditionalText
'
,
additionalText
:
'
Test_AdditionalText
'
,
},
},
},
id
:
1
,
},
label
:
'
TEST
'
,
id
:
1
,
wantAgent
:
wantAgentObj
,
label
:
'
TEST
'
,
wantAgent
:
wantAgentObj
,
}
}
```
5.
发布WantAgent通知。
```
ts
notificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
// 通知发送
if
(
err
)
{
NotificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
console
.
error
(
`Failed to publish notification. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
if
(
err
)
{
return
;
console
.
error
(
`[ANS] failed to publish, error[
${
err
}
]`
);
}
return
;
console
.
info
(
'
Succeeded in publishing notification.
'
);
}
console
.
info
(
`[ANS] publish success `
);
});
});
```
```
6.
用户通过点击通知栏上的通知,触发WantAgent的动作。
6.
用户通过点击通知栏上的通知,系统会自动触发WantAgent的动作。
```
ts
// 触发WantAgent
let
triggerInfo
=
{
code
:
0
}
wantAgent
.
trigger
(
wantAgentObj
,
triggerInfo
,
(
completeData
)
=>
{
console
.
info
(
'
[WantAgent]getWantAgent success, completeData:
'
,
+
JSON
.
stringify
(
completeData
));
});
```
zh-cn/application-dev/notification/progress-bar-notification.md
浏览文件 @
2a3261ae
...
@@ -5,16 +5,16 @@
...
@@ -5,16 +5,16 @@
目前系统模板仅支持进度条模板,通知模板
[
NotificationTemplate
](
../reference/apis/js-apis-inner-notification-notificationTemplate.md
)
中的data参数为用户自定义数据,用于显示与模块相关的数据,效果示意如下图所示。
目前系统模板仅支持进度条模板,通知模板
[
NotificationTemplate
](
../reference/apis/js-apis-inner-notification-notificationTemplate.md
)
中的data参数为用户自定义数据,用于显示与模块相关的数据,效果示意如下图所示。
**图1**
进度条通知效果示意图


## 接口说明
## 接口说明
[
isSupportTemplate()
](
../reference/apis/js-apis-notificationManager.md#notification
issupporttemplate
)
是查询模板是否支持接口,目前仅支持进度条模板。
[
`isSupportTemplate()`
](
../reference/apis/js-apis-notificationManager.md#notificationmanager
issupporttemplate
)
是查询模板是否支持接口,目前仅支持进度条模板。
| | |
| -------- | -------- |
|
**接口名**
|
**描述**
|
|
**接口名**
|
**描述**
|
| -------- | -------- |
| isSupportTemplate(templateName:
string,
callback:
AsyncCallback
<
boolean
>
):
void | 查询模板是否存在。 |
| isSupportTemplate(templateName:
string,
callback:
AsyncCallback
<
boolean
>
):
void | 查询模板是否存在。 |
...
@@ -25,31 +25,32 @@
...
@@ -25,31 +25,32 @@
2.
导入模块。
2.
导入模块。
```
ts
```
ts
import
N
otificationManager
from
'
@ohos.notificationManager
'
;
import
n
otificationManager
from
'
@ohos.notificationManager
'
;
```
```
3.
查询系统是否支持进度条模板,查询结果为支持downloadTemplate模板类通知。
3.
查询系统是否支持进度条模板,查询结果为支持downloadTemplate模板类通知。
```
ts
```
ts
N
otificationManager
.
isSupportTemplate
(
'
downloadTemplate
'
).
then
((
data
)
=>
{
n
otificationManager
.
isSupportTemplate
(
'
downloadTemplate
'
).
then
((
data
)
=>
{
console
.
info
(
`[ANS] isSupportTemplate success`
);
console
.
info
(
`[ANS] isSupportTemplate success`
);
console
.
info
(
'
Succeeded in supporting download template notification.
'
);
let
isSupportTpl
:
boolean
=
data
;
// isSupportTpl的值为true表示支持支持downloadTemplate模板类通知,false表示不支持
let
isSupportTpl
:
boolean
=
data
;
// isSupportTpl的值为true表示支持支持downloadTemplate模板类通知,false表示不支持
// ...
// ...
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
`
[ANS] isSupportTemplate failed, error[
${
err
}
]
`
);
console
.
error
(
`
Failed to support download template notification. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
});
```
```
>

**说明:**
> **说明:**
> 查询系统支持进度条模板后,再进行后续的步骤操作。
> 查询系统支持进度条模板后,再进行后续的步骤操作。
4.
构造进度条模板对象,并发布通知。
4.
构造进度条模板对象,并发布通知。
```
ts
```
ts
let
notificationRequest
=
{
let
notificationRequest
:
notificationManager
.
NotificationRequest
=
{
id
:
1
,
id
:
1
,
content
:
{
content
:
{
contentType
:
N
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_BASIC_TEXT
,
contentType
:
n
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_BASIC_TEXT
,
normal
:
{
normal
:
{
title
:
'
test_title
'
,
title
:
'
test_title
'
,
text
:
'
test_text
'
,
text
:
'
test_text
'
,
...
@@ -64,11 +65,11 @@
...
@@ -64,11 +65,11 @@
}
}
// 发布通知
// 发布通知
N
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
n
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
`
[ANS] failed to publish, error[
${
err
}
]
`
);
console
.
error
(
`
Failed to publish notification. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
return
;
}
}
console
.
info
(
`[ANS] publish success `
);
console
.
info
(
'
Succeeded in publishing notification.
'
);
});
});
```
```
zh-cn/application-dev/notification/text-notification.md
浏览文件 @
2a3261ae
...
@@ -3,8 +3,7 @@
...
@@ -3,8 +3,7 @@
基础类型通知主要应用于发送短信息、提示信息、广告推送等,支持普通文本类型、长文本类型、多行文本类型和图片类型。
基础类型通知主要应用于发送短信息、提示信息、广告推送等,支持普通文本类型、长文本类型、多行文本类型和图片类型。
**表1**
基础类型通知中的内容分类
**表1**
基础类型通知中的内容分类
| 类型 | 描述 |
| 类型 | 描述 |
| -------- | -------- |
| -------- | -------- |
...
@@ -13,16 +12,15 @@
...
@@ -13,16 +12,15 @@
| NOTIFICATION_CONTENT_MULTILINE | 多行文本类型。 |
| NOTIFICATION_CONTENT_MULTILINE | 多行文本类型。 |
| NOTIFICATION_CONTENT_PICTURE | 图片类型。 |
| NOTIFICATION_CONTENT_PICTURE | 图片类型。 |
目前,系统仅支持通知栏订阅通知,将通知显示在通知栏中。基本类型通知的效果示意如下图所示。
目前系统仅通知栏订阅了通知,将通知显示在通知栏里。基础类型通知呈现效果示意图如下所示。
**图1**
基础类型通知呈现效果示意图

**图1**
基础类型通知呈现效果示意图 !
[
zh-cn_image_0000001466462305
](
figures/zh-cn_image_0000001466462305.png
)
## 接口说明
## 接口说明
通知发布接口如下表所示,不同发布类型通知由
[
NotificationRequest
](
../reference/apis/js-apis-
notification
.md#notificationrequest
)
的字段携带不同的信息。
通知发布接口如下表所示,不同发布类型通知由
[
NotificationRequest
](
../reference/apis/js-apis-
inner-notification-notificationRequest
.md#notificationrequest
)
的字段携带不同的信息。
|
**接口名**
|
**描述**
|
|
**接口名**
|
**描述**
|
| -------- | -------- |
| -------- | -------- |
...
@@ -38,124 +36,123 @@
...
@@ -38,124 +36,123 @@
2.
导入模块。
2.
导入模块。
```
ts
```
ts
import
N
otificationManager
from
'
@ohos.notificationManager
'
;
import
n
otificationManager
from
'
@ohos.notificationManager
'
;
```
```
3.
构造NotificationRequest对象,并发布通知。
3.
构造NotificationRequest对象,并发布通知。
-
普通文本类型通知由标题、文本内容和附加信息三个字段组成,其中标题和文本内容是必填字段,大小均需要小于200字节。
-
普通文本类型通知由标题、文本内容和附加信息三个字段组成,其中标题和文本内容是必填字段,大小均需要小于200字节。
```
ts
```
ts
let
notificationRequest
=
{
let
notificationRequest
:
notificationManager
.
NotificationRequest
=
{
id
:
1
,
id
:
1
,
content
:
{
content
:
{
contentType
:
N
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_BASIC_TEXT
,
// 普通文本类型通知
contentType
:
n
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_BASIC_TEXT
,
// 普通文本类型通知
normal
:
{
normal
:
{
title
:
'
test_title
'
,
title
:
'
test_title
'
,
text
:
'
test_text
'
,
text
:
'
test_text
'
,
additionalText
:
'
test_additionalText
'
,
additionalText
:
'
test_additionalText
'
,
}
}
}
}
}
}
;
N
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
n
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
`[ANS] failed to publish, error[
${
err
}
]
`
);
console
.
error
(
`Failed to publish notification. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
return
;
}
}
console
.
info
(
`[ANS] publish success`
);
console
.
info
(
'
Succeeded in publishing notification.
'
);
});
});
```
```
运行效果如下图所示。
运行效果如下图所示。


-
长文本类型通知继承了普通文本类型的字段,同时新增了长文本内容、内容概要和通知展开时的标题,其中长文本内容不超过1024字节,其他字段小于200字节。通知默认显示与普通文本相同,展开后,标题显示为展开后标题内容,内容为长文本内容。
-
长文本类型通知继承了普通文本类型的字段,同时新增了长文本内容、内容概要和通知展开时的标题,其中长文本内容不超过1024字节,其他字段小于200字节。通知默认显示与普通文本相同,展开后,标题显示为展开后标题内容,内容为长文本内容。
```
ts
```
ts
let
notificationRequest
=
{
let
notificationRequest
:
notificationManager
.
NotificationRequest
=
{
id
:
1
,
id
:
1
,
content
:
{
content
:
{
contentType
:
N
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_LONG_TEXT
,
// 长文本类型通知
contentType
:
n
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_LONG_TEXT
,
// 长文本类型通知
longText
:
{
longText
:
{
title
:
'
test_title
'
,
title
:
'
test_title
'
,
text
:
'
test_text
'
,
text
:
'
test_text
'
,
additionalText
:
'
test_additionalText
'
,
additionalText
:
'
test_additionalText
'
,
longText
:
'
test_longText
'
,
longText
:
'
test_longText
'
,
briefText
:
'
test_briefText
'
,
briefText
:
'
test_briefText
'
,
expandedTitle
:
'
test_expandedTitle
'
,
expandedTitle
:
'
test_expandedTitle
'
,
}
}
}
}
}
}
;
// 发布通知
// 发布通知
N
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
n
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
`[ANS] failed to publish, error[
${
err
}
]
`
);
console
.
error
(
`Failed to publish notification. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
return
;
}
}
console
.
info
(
`[ANS] publish success`
);
console
.
info
(
'
Succeeded in publishing notification.
'
);
});
});
```
```
运行效果如下图所示。
运行效果如下图所示。
!
[
zh-cn_image_0000001416745530
](
figures/zh-cn_image_0000001416745530.png
)
!
[
zh-cn_image_0000001416745530
](
figures/zh-cn_image_0000001416745530.png
)
-
多行文本类型通知继承了普通文本类型的字段,同时新增了多行文本内容、内容概要和通知展开时的标题,其字段均小于200字节。通知默认显示与普通文本相同,展开后,标题显示为展开后标题内容,多行文本内容多行显示。
-
多行文本类型通知继承了普通文本类型的字段,同时新增了多行文本内容、内容概要和通知展开时的标题,其字段均小于200字节。通知默认显示与普通文本相同,展开后,标题显示为展开后标题内容,多行文本内容多行显示。
```
ts
```
ts
let
notificationRequest
=
{
let
notificationRequest
:
notificationManager
.
NotificationRequest
=
{
id
:
1
,
id
:
1
,
content
:
{
content
:
{
contentType
:
N
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_MULTILINE
,
// 多行文本类型通知
contentType
:
n
otificationManager
.
ContentType
.
NOTIFICATION_CONTENT_MULTILINE
,
// 多行文本类型通知
multiLine
:
{
multiLine
:
{
title
:
'
test_title
'
,
title
:
'
test_title
'
,
text
:
'
test_text
'
,
text
:
'
test_text
'
,
briefText
:
'
test_briefText
'
,
briefText
:
'
test_briefText
'
,
longTitle
:
'
test_longTitle
'
,
longTitle
:
'
test_longTitle
'
,
lines
:
[
'
line_01
'
,
'
line_02
'
,
'
line_03
'
,
'
line_04
'
],
lines
:
[
'
line_01
'
,
'
line_02
'
,
'
line_03
'
,
'
line_04
'
],
}
}
}
}
}
}
;
// 发布通知
// 发布通知
N
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
n
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
`[ANS] failed to publish, error[
${
err
}
]
`
);
console
.
error
(
`Failed to publish notification. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
return
;
}
}
console
.
info
(
`[ANS] publish success`
);
console
.
info
(
'
Succeeded in publishing notification.
'
);
});
});
```
```
运行效果如下图所示。
运行效果如下图所示。
!
[
zh-cn_image_0000001417062446
](
figures/zh-cn_image_0000001417062446.png
)
!
[
zh-cn_image_0000001417062446
](
figures/zh-cn_image_0000001417062446.png
)
-
图片类型通知继承了普通文本类型的字段,同时新增了图片内容、内容概要和通知展开时的标题,图片内容为
PixelMap
型对象,其大小不能超过2M。
-
图片类型通知继承了普通文本类型的字段,同时新增了图片内容、内容概要和通知展开时的标题,图片内容为
[
PixelMap
](
../reference/apis/js-apis-image.md#pixelmap7
)
类
型对象,其大小不能超过2M。
```
ts
```
ts
let
notificationPicture
:
PixelMap
=
undefined
;
// 需要获取图片PixelMap信息
let
imagePixelMap
:
PixelMap
=
undefined
;
// 需要获取图片PixelMap信息
let
notificationRequest
=
{
let
notificationRequest
:
notificationManager
.
NotificationRequest
=
{
id
:
1
,
id
:
1
,
content
:
{
content
:
{
contentType
:
NotificationManager
.
ContentType
.
NOTIFICATION_CONTENT_PICTURE
,
contentType
:
notificationManager
.
ContentType
.
NOTIFICATION_CONTENT_PICTURE
,
picture
:
{
picture
:
{
title
:
'
test_title
'
,
title
:
'
test_title
'
,
text
:
'
test_text
'
,
text
:
'
test_text
'
,
additionalText
:
'
test_additionalText
'
,
additionalText
:
'
test_additionalText
'
,
briefText
:
'
test_briefText
'
,
briefText
:
'
test_briefText
'
,
expandedTitle
:
'
test_expandedTitle
'
,
expandedTitle
:
'
test_expandedTitle
'
,
picture
:
notificationPicture
picture
:
imagePixelMap
}
}
}
}
}
};
// 发布通知
// 发布通知
N
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
n
otificationManager
.
publish
(
notificationRequest
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
`[ANS] failed to publish, error[
${
err
}
]
`
);
console
.
error
(
`Failed to publish notification. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
return
;
}
}
console
.
info
(
`[ANS] publish success `
);
console
.
info
(
'
Succeeded in publishing notification.
'
);
});
});
```
```
运行效果如下图所示。
运行效果如下图所示。
!
[
zh-cn_image_0000001466582045
](
figures/zh-cn_image_0000001466582045.png
)
!
[
zh-cn_image_0000001466582045
](
figures/zh-cn_image_0000001466582045.png
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录