diff --git a/zh-cn/application-dev/application-models/common-event-overview.md b/zh-cn/application-dev/application-models/common-event-overview.md index 08445abe772f5863b17dc68cc1cf2c20232128ac..4789a84f3cb05653c0dc5778e5be10445d2098c5 100644 --- a/zh-cn/application-dev/application-models/common-event-overview.md +++ b/zh-cn/application-dev/application-models/common-event-overview.md @@ -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#配置文件权限声明)。 diff --git a/zh-cn/application-dev/application-models/process-model-stage.md b/zh-cn/application-dev/application-models/process-model-stage.md index 0717b4c02d45622ddb2606ee7f0b6c6f0bda4ecf..cf030e0ba0931f75a7ebd64757d8a355b8df36a1 100644 --- a/zh-cn/application-dev/application-models/process-model-stage.md +++ b/zh-cn/application-dev/application-models/process-model-stage.md @@ -1,16 +1,17 @@ # 进程模型概述 -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** 进程模型示意图 ![process-model](figures/process-model.png) > 说明: @@ -20,7 +21,7 @@ OpenHarmony的进程模型如下图所示: 在上述模型基础上,对于系统应用可以通过申请多进程权限(如下图所示),为指定HAP配置一个自定义进程名,该HAP中的UIAbility、DataShareExtensionAbility、ServiceExtensionAbility就会运行在自定义进程中。不同的HAP可以通过配置不同的进程名运行在不同进程中。 - **图2** 多进程示意图 +**图2** 多进程示意图 ![multi-process](figures/multi-process.png) @@ -29,4 +30,4 @@ OpenHarmony的进程模型如下图所示: - [公共事件机制](common-event-overview.md):多用于一对多的通信场景,公共事件发布者可能存在多个订阅者同时接收事件。 -- [后台服务机制](background-services.md):当前主要通过[ServiceExtensionAbility](serviceextensionability.md)的能力实现。 +- [后台服务机制](background-services.md):通过[ServiceExtensionAbility](serviceextensionability.md)的能力实现。 diff --git a/zh-cn/application-dev/application-models/thread-model-stage.md b/zh-cn/application-dev/application-models/thread-model-stage.md index b05ced9d92e3d3578e2b29de3aea52fd4ea99718..57ac44d934cee35e9b57e1a67bd8dd8047fa239a 100644 --- a/zh-cn/application-dev/application-models/thread-model-stage.md +++ b/zh-cn/application-dev/application-models/thread-model-stage.md @@ -2,19 +2,20 @@ 在OpenHarmony应用中,每个进程都会有一个主线程,主线程具有以下职责: -1. 执行UI绘制; -2. 管理主线程的ArkTS引擎实例,使多个UIAbility组件能够运行在其之上; -3. 管理其他线程(例如Worker线程)的ArkTS引擎实例,例如启动和终止其他线程; -4. 分发交互事件; -5. 处理应用代码的回调,包括事件处理和生命周期管理; -6. 接收Worker线程发送的消息; +1. 执行UI绘制。 +2. 管理主线程的ArkTS引擎实例,使多个UIAbility组件能够运行在其之上。 +3. 管理其他线程(例如Worker线程)的ArkTS引擎实例,例如启动和终止其他线程。 +4. 分发交互事件。 +5. 处理应用代码的回调,包括事件处理和生命周期管理。 +6. 接收Worker线程发送的消息。 除了主线程外,还有一类独立的Worker线程,用于执行耗时操作。Worker线程在主线程中创建,与主线程相互独立,但不能直接操作UI。最多可以创建7个Worker线程。 ![thread-model-stage](figures/thread-model-stage.png) -基于OpenHarmony的线程模型,不同的业务功能运行在不同的线程上,业务功能的交互就需要线程间通信。同一个进程内,线程间通信目前主要有Emitter和Worker两种方式,其中Emitter主要适用于线程间的事件同步, Worker主要用于新开一个线程执行耗时任务。 +基于OpenHarmony的线程模型,不同的业务功能运行在不同的线程上,业务功能的交互就需要线程间通信。同一个进程内,线程间通信目前主要有Emitter和Worker两种方式,其中Emitter主要适用于线程间的事件同步,Worker主要用于新开一个线程执行耗时任务。 > **说明:** > -> - Stage模型只提供了主线程和Worker线程,Emitter主要用于主线程内或者主线程和Worker线程的事件同步。 -> - 执行`hdc shell`命令,进入设备的shell命令行。在shell命令行中,执行`ps -p -T`命令,可以查看指定应用进程的线程信息。其中,``为需要指定的应用进程的进程ID。 +> - Stage模型只提供了主线程和Worker线程,Emitter主要用于主线程和Worker线程、Worker线程和Worker线程之间的事件同步。 +> - UIAbility组件与UI均在主线程中,他们之间的数据同步请参见[UIAbility组件与UI的数据同步](uiability-data-sync-with-ui.md)。 +> - 执行`hdc shell`命令,进入设备的shell命令行。在shell命令行中,执行`ps -p -T`命令,可以查看指定应用进程的线程信息。其中,``为需要指定的应用进程的[进程ID](process-model-stage.md)。 diff --git a/zh-cn/application-dev/notification/Readme-CN.md b/zh-cn/application-dev/notification/Readme-CN.md index 37198818a00d30ab34dbe5c475a2ab7f1bf9495b..fd7aa8a9aa58543d263d517283b892407a8a2068 100644 --- a/zh-cn/application-dev/notification/Readme-CN.md +++ b/zh-cn/application-dev/notification/Readme-CN.md @@ -3,7 +3,7 @@ - [通知概述](notification-overview.md) - [订阅通知(仅对系统应用开放)](notification-subscription.md) - [使能通知开关](notification-enable.md) -- [通知角标](notification-badge.md) +- [设置通知角标](notification-badge.md) - 发布通知 - [发布基础类型通知](text-notification.md) - [发布进度条类型通知](progress-bar-notification.md) diff --git a/zh-cn/application-dev/notification/figures/zh-cn_image_0000001466462305.png b/zh-cn/application-dev/notification/figures/zh-cn_image_0000001466462305.png index 2c580f75dc86159b4088e54d3f83e163fd352f6d..f879ad7ef01a39b5f18af8abea3f7f1842b2b446 100644 Binary files a/zh-cn/application-dev/notification/figures/zh-cn_image_0000001466462305.png and b/zh-cn/application-dev/notification/figures/zh-cn_image_0000001466462305.png differ diff --git a/zh-cn/application-dev/notification/notification-badge.md b/zh-cn/application-dev/notification/notification-badge.md index 719dd9b5c1481481b8f3a9819470eb25723b0e05..d113365cf398d36863ba722739147a7c53bfc61e 100644 --- a/zh-cn/application-dev/notification/notification-badge.md +++ b/zh-cn/application-dev/notification/notification-badge.md @@ -11,11 +11,11 @@ 1. 通知服务提供了两种增加角标数的方法: - - 发布通知时,在[NotificationRequest](../reference/apis/js-apis-notificationManager.md#notificationrequest)的badgeNumber字段里携带,桌面收到通知后,在原角标数上累加、呈现。 + - 发布通知时,在[NotificationRequest](../reference/apis/js-apis-inner-notification-notificationRequest.md#notificationrequest)的badgeNumber字段里携带,桌面收到通知后,在原角标数上累加、呈现。 - - 调用接口[setBadgeNumber](../reference/apis/js-apis-notificationManager.md#setbadgenumber)设置,桌面按设置的角标数呈现。 + - 调用接口[`setBadgeNumber()`](../reference/apis/js-apis-notificationManager.md#notificationmanagersetbadgenumber10)设置,桌面按设置的角标数呈现。 -2. 角标数减少,目前仅支持通过[setBadgeNumber](../reference/apis/js-apis-notificationManager.md#setbadgenumber)设置。 +2. 角标数减少,目前仅支持通过[`setBadgeNumber()`](../reference/apis/js-apis-notificationManager.md#notificationmanagersetbadgenumber10)设置。 | **接口名** | **描述** | | -------- | -------- | @@ -32,39 +32,38 @@ 2. 增加角标个数。 - 发布通知在[NotificationRequest](../reference/apis/js-apis-notificationManager.md#notificationrequest)的badgeNumber字段里携带,可参考[通知发布](text-notification.md)章节。 + 发布通知在[NotificationRequest](../reference/apis/js-apis-inner-notification-notificationRequest.md#notificationrequest)的badgeNumber字段里携带,可参考[通知发布](text-notification.md)章节。 示例为调用setBadgeNumber接口增加角标,在发布完新的通知后,调用该接口。 ```ts function setBadgeNumberCallback(err) { - if (err) { - console.info(`Set badge failed code is ${err.code}, message is ${err.message}`); - } else { - console.info(`Set badge success`); - } + if (err) { + console.error(`Failed to set badge number. Code is ${err.code}, message is ${err.message}`); + return; + } + console.info(`Succeeded in seting badge number.`); } - let badgeNumber = 10 + let badgeNumber = 10; notificationManager.setBadgeNumber(badgeNumber, setBadgeNumberCallback); ``` -3. 减少角标个数 +3. 减少角标个数。 一条通知被查看后,应用需要调用接口设置剩下未读通知个数,桌面刷新角标。 ```ts function setBadgeNumberCallback(err) { - if (err) { - console.info(`Set badge failed code is ${err.code}, message is ${err.message}`); - } else { - console.info(`Set badge success`); - } + if (err) { + console.error(`Failed to set badge number. Code is ${err.code}, message is ${err.message}`); + return; + } + console.info(`Succeeded in seting badge number.`); } - let badgeNumber = 9 + let badgeNumber = 9; notificationManager.setBadgeNumber(badgeNumber, setBadgeNumberCallback); ``` - diff --git a/zh-cn/application-dev/notification/notification-enable.md b/zh-cn/application-dev/notification/notification-enable.md index 8979f708736def28a8fbf84dbcffbe513af146f8..45d3345c19810f5e0c2dfce772cf1e9a378d8339 100644 --- a/zh-cn/application-dev/notification/notification-enable.md +++ b/zh-cn/application-dev/notification/notification-enable.md @@ -1,7 +1,7 @@ # 使能通知开关 -应用需要开启通知开关才能发送通知。开发者可以在通知发布前调用[requestEnableNotification()](../reference/apis/js-apis-notificationManager.md#notificationrequestenablenotification)方法,弹窗让用户选择是否开启使能开关,仅弹窗一次,后续调用该接口不再弹窗。 +应用需要开启通知开关才能发送通知。开发者可以在通知发布前调用[requestEnableNotification()](../reference/apis/js-apis-notificationManager.md#notificationmanagerrequestenablenotification)方法,弹窗让用户选择是否开启使能开关,仅弹窗一次,后续调用该接口不再弹窗。 **图1** 使能通知开关示意图 ![zh-cn_image_0000001416585590](figures/zh-cn_image_0000001416585590.png) @@ -9,7 +9,7 @@ - 点击“允许”后,则表示允许应用发送通知。 -- 点击“取消”后,再次调用[requestEnableNotification()](../reference/apis/js-apis-notificationManager.md#notificationrequestenablenotification)方法,则不再弹窗。此时如需要手动使能通知开关,操作步骤如下所示。 +- 点击“取消”后,再次调用[requestEnableNotification()](../reference/apis/js-apis-notificationManager.md#notificationmanagerrequestenablenotification)方法,则不再弹窗。此时如需要手动使能通知开关,操作步骤如下所示。 | ①从设备左上方下拉,进入通知界面 | ②点击右上角“设置”图标,进入通知界面,找到需要打开通知开关的应用 | ③打开“允许通知”开关 | | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | diff --git a/zh-cn/application-dev/notification/notification-overview.md b/zh-cn/application-dev/notification/notification-overview.md index 18cfacc8a97bc17ab063a9046c5196a31faa2e19..8d94d296892616eae51485476ce4f2aead49df44 100644 --- a/zh-cn/application-dev/notification/notification-overview.md +++ b/zh-cn/application-dev/notification/notification-overview.md @@ -13,7 +13,7 @@ - 显示当前正在进行的事件,如下载等。 -OpenHarmony通过ANS(Advanced Notification Service,通知系统服务)对通知类型的消息进行管理,支持多种通知类型,如基础类型通知、进度条类型通知、后台代理提醒。 +OpenHarmony通过ANS(Advanced Notification Service,通知系统服务)对通知类型的消息进行管理,支持多种通知类型,例如基础类型通知、进度条类型通知、后台代理提醒。 ## 通知业务流程 @@ -24,6 +24,7 @@ OpenHarmony通过ANS(Advanced Notification Service,通知系统服务)对 系统应用还支持通知相关配置,如使能开关、配置参数由系统配置发起请求,发送到通知子系统存储到内存和数据库。 +**图1** 通知业务流程 ![zh-cn_image_0000001466582017](figures/zh-cn_image_0000001466582017.png) ## 相关实例 diff --git a/zh-cn/application-dev/notification/notification-subscription.md b/zh-cn/application-dev/notification/notification-subscription.md index 04b69d9fbaf76f42e1f0228909046ddd663cdfd7..33db2db09dc8ca0489f79ce12d6c2fff14789138 100644 --- a/zh-cn/application-dev/notification/notification-subscription.md +++ b/zh-cn/application-dev/notification/notification-subscription.md @@ -46,37 +46,38 @@ ```ts let subscriber = { - onConsume: function (data) { - let req = data.request; - console.info('[ANS] onConsume callback req.id: ' + req.id); - }, - onCancel: function (data) { - let req = data.request; - console.info('[ANS] onCancel callback req.id: : ' + req.id); - }, - onUpdate: function (data) { - console.info('[ANS] onUpdate in test'); - }, - onConnect: function () { - console.info('[ANS] onConnect in test'); - }, - onDisconnect: function () { - console.info('[ANS] onDisConnect in test'); - }, - onDestroy: function () { - console.info('[ANS] onDestroy in test'); - }, + onConsume: function (data) { + let req = data.request; + console.info(`onConsume callback. req.id: ${req.id}`); + }, + onCancel: function (data) { + let req = data.request; + console.info(`onCancel callback. req.id: ${req.id}`); + }, + onUpdate: function (data) { + let req = data.request; + console.info(`onUpdate callback. req.id: ${req.id}`); + }, + onConnect: function () { + console.info(`onConnect callback.}`); + }, + onDisconnect: function () { + console.info(`onDisconnect callback.}`); + }, + onDestroy: function () { + console.info(`onDestroy callback.}`); + }, }; ``` - + 4. 发起通知订阅。 ```ts notificationSubscribe.subscribe(subscriber, (err, data) => { // callback形式调用异步接口 if (err) { - console.error(`[ANS] subscribe failed, code is ${err.code}, message is ${err.message}`); + console.error(`Failed to subscribe notification. Code is ${err.code}, message is ${err.message}`); return; } - console.info(`[ANS] subscribeTest success : + ${data}`); + console.info(`Succeeded in subscribing to notification. Data: ${data}`); }); ``` diff --git a/zh-cn/application-dev/notification/notification-with-wantagent.md b/zh-cn/application-dev/notification/notification-with-wantagent.md index d3ea33340bf8af7a738c2655abd892d1a67b6357..4b3a00ff7ceefb580ba2b6e1aff051ea95f45c93 100644 --- a/zh-cn/application-dev/notification/notification-with-wantagent.md +++ b/zh-cn/application-dev/notification/notification-with-wantagent.md @@ -4,7 +4,7 @@ 为通知添加行为意图的实现方式如下图所示:发布通知的应用向应用组件管理服务AMS(Ability Manager Service)申请[WantAgent](../reference/apis/js-apis-app-ability-wantAgent.md),然后随其他通知信息一起发送给桌面,当用户在桌面通知栏上点击通知时,触发[WantAgent](../reference/apis/js-apis-app-ability-wantAgent.md)动作。 - **图1** 携带行为意图的通知运行机制 +**图1** 携带行为意图的通知运行机制 ![notification-with-wantagent](figures/notification-with-wantagent.png) @@ -41,20 +41,20 @@ // 通过WantAgentInfo的operationType设置动作类型 let wantAgentInfo = { - wants: [ - { - deviceId: '', - bundleName: 'com.example.myapplication', - abilityName: 'EntryAbility', - action: '', - entities: [], - uri: '', - parameters: {} - } - ], - operationType: wantAgent.OperationType.START_ABILITY, - requestCode: 0, - wantAgentFlags:[wantAgent.WantAgentFlags.CONSTANT_FLAG] + wants: [ + { + deviceId: '', + bundleName: 'com.example.myapplication', + abilityName: 'EntryAbility', + action: '', + entities: [], + uri: '', + parameters: {} + } + ], + operationType: wantAgent.OperationType.START_ABILITY, + requestCode: 0, + wantAgentFlags:[wantAgent.WantAgentFlags.CONSTANT_FLAG] }; ``` @@ -65,16 +65,16 @@ // 通过WantAgentInfo的operationType设置动作类型 let wantAgentInfo = { - wants: [ - { - action: 'event_name', // 设置事件名 - parameters: {}, - } - ], - operationType: wantAgent.OperationType.SEND_COMMON_EVENT, - requestCode: 0, - wantAgentFlags: [wantAgent.WantAgentFlags.CONSTANT_FLAG], - } + wants: [ + { + action: 'event_name', // 设置事件名 + parameters: {}, + } + ], + operationType: wantAgent.OperationType.SEND_COMMON_EVENT, + requestCode: 0, + wantAgentFlags: [wantAgent.WantAgentFlags.CONSTANT_FLAG], + }; ``` 4. 调用[getWantAgent()](../reference/apis/js-apis-app-ability-wantAgent.md#wantagentgetwantagent)方法进行创建WantAgent。 @@ -82,12 +82,12 @@ ```typescript // 创建WantAgent wantAgent.getWantAgent(wantAgentInfo, (err, data) => { - if (err) { - console.error('[WantAgent]getWantAgent err=' + JSON.stringify(err)); - return; - } - console.info('[WantAgent]getWantAgent success'); - wantAgentObj = data; + if (err) { + console.error(`Failed to get want agent. Code is ${err.code}, message is ${err.message}`); + return; + } + console.info('Succeeded in geting want agent.'); + wantAgentObj = data; }); ``` @@ -96,25 +96,25 @@ ```typescript // 构造NotificationRequest对象 let notificationRequest: notificationManager.NotificationRequest = { - content: { - contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, - normal: { - title: 'Test_Title', - text: 'Test_Text', - additionalText: 'Test_AdditionalText', - }, + content: { + contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: 'Test_Title', + text: 'Test_Text', + additionalText: 'Test_AdditionalText', }, - id: 1, - label: 'TEST', - wantAgent: wantAgentObj, + }, + id: 1, + label: 'TEST', + wantAgent: wantAgentObj, } notificationManager.publish(notificationRequest, (err) => { - if (err) { - console.error(`[ANS] publish failed, code is ${err.code}, message is ${err.message}`); - return; - } - console.info(`[ANS] publish success`); + if (err) { + console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); + return; + } + console.info('Succeeded in publishing notification.'); }); ``` diff --git a/zh-cn/application-dev/notification/progress-bar-notification.md b/zh-cn/application-dev/notification/progress-bar-notification.md index 69da9774cda1cd37d28e08fd99e4870011a07147..d5720422d429fea4edf5f0da01309ac4127ecdf2 100644 --- a/zh-cn/application-dev/notification/progress-bar-notification.md +++ b/zh-cn/application-dev/notification/progress-bar-notification.md @@ -5,12 +5,13 @@ 目前系统模板仅支持进度条模板,通知模板[NotificationTemplate](../reference/apis/js-apis-inner-notification-notificationTemplate.md)中的data参数为用户自定义数据,用于显示与模块相关的数据,效果示意如下图所示。 +**图1** 进度条通知效果示意图 ![zh-cn_image_0000001416903138](figures/zh-cn_image_0000001416903138.png) ## 接口说明 -[isSupportTemplate()](../reference/apis/js-apis-notificationManager.md#notificationmanagerissupporttemplate)是查询模板是否支持接口,目前仅支持进度条模板。 +[`isSupportTemplate()`](../reference/apis/js-apis-notificationManager.md#notificationmanagerissupporttemplate)是查询模板是否支持接口,目前仅支持进度条模板。 | **接口名** | **描述** | | -------- | -------- | @@ -32,16 +33,17 @@ ```ts notificationManager.isSupportTemplate('downloadTemplate').then((data) => { console.info(`[ANS] isSupportTemplate success`); + console.info('Succeeded in supporting download template notification.'); let isSupportTpl: boolean = data; // isSupportTpl的值为true表示支持支持downloadTemplate模板类通知,false表示不支持 // ... }).catch((err) => { - console.error(`[ANS] isSupportTemplate failed, code is ${err.code}, message is ${err.message}`); + console.error(`Failed to support download template notification. Code is ${err.code}, message is ${err.message}`); }); ``` - + > **说明:** > 查询系统支持进度条模板后,再进行后续的步骤操作。 - + 4. 构造进度条模板对象,并发布通知。 ```ts @@ -65,9 +67,9 @@ // 发布通知 notificationManager.publish(notificationRequest, (err) => { if (err) { - console.error(`[ANS] publish failed, code is ${err.code}, message is ${err.message}`); + console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); return; } - console.info(`[ANS] publish success `); + console.info('Succeeded in publishing notification.'); }); ``` diff --git a/zh-cn/application-dev/notification/text-notification.md b/zh-cn/application-dev/notification/text-notification.md index cd36636bb4fc749bc7db374df6a0c319f3df88c2..7685eecf65bb5030d7c2615d57f8c91e0d9713b2 100644 --- a/zh-cn/application-dev/notification/text-notification.md +++ b/zh-cn/application-dev/notification/text-notification.md @@ -3,8 +3,7 @@ 基础类型通知主要应用于发送短信息、提示信息、广告推送等,支持普通文本类型、长文本类型、多行文本类型和图片类型。 - - **表1** 基础类型通知中的内容分类 +**表1** 基础类型通知中的内容分类 | 类型 | 描述 | | -------- | -------- | @@ -13,8 +12,7 @@ | NOTIFICATION_CONTENT_MULTILINE | 多行文本类型。 | | NOTIFICATION_CONTENT_PICTURE | 图片类型。 | - -目前系统仅通知栏订阅了通知,将通知显示在通知栏里。基础类型通知呈现效果示意图如下所示。 +目前,系统仅支持通知栏订阅通知,将通知显示在通知栏中。基本类型通知的效果示意如下图所示。 **图1** 基础类型通知呈现效果示意图 ![zh-cn_image_0000001466462305](figures/zh-cn_image_0000001466462305.png) @@ -22,7 +20,7 @@ ## 接口说明 -通知发布接口如下表所示,不同发布类型通知由[NotificationRequest](../reference/apis/js-apis-notificationManager.md#notificationrequest)的字段携带不同的信息。 +通知发布接口如下表所示,不同发布类型通知由[NotificationRequest](../reference/apis/js-apis-inner-notification-notificationRequest.md#notificationrequest)的字段携带不同的信息。 | **接口名** | **描述** | | -------- | -------- | @@ -48,21 +46,21 @@ let notificationRequest: notificationManager.NotificationRequest = { id: 1, content: { - contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, // 普通文本类型通知 - normal: { - title: 'test_title', - text: 'test_text', - additionalText: 'test_additionalText', - } + contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, // 普通文本类型通知 + normal: { + title: 'test_title', + text: 'test_text', + additionalText: 'test_additionalText', + } } - } + }; notificationManager.publish(notificationRequest, (err) => { - if (err) { - console.error(`[ANS] publish failed, code is ${err.code}, message is ${err.message}`); - return; - } - console.info(`[ANS] publish success.`); + if (err) { + console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); + return; + } + console.info('Succeeded in publishing notification.'); }); ``` @@ -74,25 +72,25 @@ let notificationRequest: notificationManager.NotificationRequest = { id: 1, content: { - contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_LONG_TEXT, // 长文本类型通知 - longText: { - title: 'test_title', - text: 'test_text', - additionalText: 'test_additionalText', - longText: 'test_longText', - briefText: 'test_briefText', - expandedTitle: 'test_expandedTitle', - } + contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_LONG_TEXT, // 长文本类型通知 + longText: { + title: 'test_title', + text: 'test_text', + additionalText: 'test_additionalText', + longText: 'test_longText', + briefText: 'test_briefText', + expandedTitle: 'test_expandedTitle', + } } - } + }; // 发布通知 notificationManager.publish(notificationRequest, (err) => { - if (err) { - console.error(`[ANS] publish failed, code is ${err.code}, message is ${err.message}`); - return; - } - console.info(`[ANS] publish success.`); + if (err) { + console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); + return; + } + console.info('Succeeded in publishing notification.'); }); ``` @@ -104,24 +102,24 @@ let notificationRequest: notificationManager.NotificationRequest = { id: 1, content: { - contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_MULTILINE, // 多行文本类型通知 - multiLine: { - title: 'test_title', - text: 'test_text', - briefText: 'test_briefText', - longTitle: 'test_longTitle', - lines: ['line_01', 'line_02', 'line_03', 'line_04'], - } + contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_MULTILINE, // 多行文本类型通知 + multiLine: { + title: 'test_title', + text: 'test_text', + briefText: 'test_briefText', + longTitle: 'test_longTitle', + lines: ['line_01', 'line_02', 'line_03', 'line_04'], + } } - } + }; // 发布通知 notificationManager.publish(notificationRequest, (err) => { if (err) { - console.error(`[ANS] publish failed, code is ${err.code}, message is ${err.message}`); - return; + console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); + return; } - console.info(`[ANS] publish success`); + console.info('Succeeded in publishing notification.'); }); ``` @@ -132,27 +130,27 @@ ```ts let imagePixelMap: PixelMap = undefined; // 需要获取图片PixelMap信息 let notificationRequest: notificationManager.NotificationRequest = { - id: 1, - content: { - contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_PICTURE, - picture: { - title: 'test_title', - text: 'test_text', - additionalText: 'test_additionalText', - briefText: 'test_briefText', - expandedTitle: 'test_expandedTitle', - picture: imagePixelMap - } + id: 1, + content: { + contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_PICTURE, + picture: { + title: 'test_title', + text: 'test_text', + additionalText: 'test_additionalText', + briefText: 'test_briefText', + expandedTitle: 'test_expandedTitle', + picture: imagePixelMap } - } + } + }; // 发布通知 notificationManager.publish(notificationRequest, (err) => { - if (err) { - console.error(`[ANS] publish failed, code is ${err.code}, message is ${err.message}`); - return; - } - console.info(`[ANS] publish success.`); + if (err) { + console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); + return; + } + console.info('Succeeded in publishing notification.'); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-notificationSubscribe.md b/zh-cn/application-dev/reference/apis/js-apis-notificationSubscribe.md index 0d986594532e10b6a7e6070b0d7db089322fabd6..c18f653787bcfad8bb5fdd9b78d2ca582dd1e447 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-notificationSubscribe.md +++ b/zh-cn/application-dev/reference/apis/js-apis-notificationSubscribe.md @@ -12,8 +12,6 @@ import notificationSubscribe from '@ohos.notificationSubscribe'; ``` - - ## NotificationSubscribe.subscribe subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\): void