diff --git a/en/application-dev/notification/notification-badge.md b/en/application-dev/notification/notification-badge.md index 5cf38e460c8db944f8608869760e3dfc63c648a7..5565df7b0561c131b0e6cde3a38868280e41770e 100644 --- a/en/application-dev/notification/notification-badge.md +++ b/en/application-dev/notification/notification-badge.md @@ -28,6 +28,7 @@ After a notification is read, the count on the badge is decremented by 1. If the ```ts import notificationManager from '@ohos.notificationManager'; + import Base from '@ohos.base'; ``` 2. Increase the count on the badge. @@ -37,7 +38,7 @@ After a notification is read, the count on the badge is decremented by 1. If the In this example, the **setBadgeNumber** API is called to add a badge. This API is called after a new notification is published. ```ts - function setBadgeNumberCallback(err) { + function setBadgeNumberCallback(err:Base.BusinessError) { if (err) { console.error(`Failed to set badge number. Code is ${err.code}, message is ${err.message}`); return; @@ -54,7 +55,7 @@ After a notification is read, the count on the badge is decremented by 1. If the After a notification is read, the application needs to call the API to set the number of remaining unread notifications. The badge is then updated. ```ts - function setBadgeNumberCallback(err) { + function setBadgeNumberCallback(err:Base.BusinessError) { if (err) { console.error(`Failed to set badge number. Code is ${err.code}, message is ${err.message}`); return; diff --git a/en/application-dev/notification/notification-enable.md b/en/application-dev/notification/notification-enable.md index 0ab05bec0d4ec44eee8f2c5c43151c2da6da51d3..64537b6dde10a3c4017282b1e93292f0ce17a367 100644 --- a/en/application-dev/notification/notification-enable.md +++ b/en/application-dev/notification/notification-enable.md @@ -36,6 +36,7 @@ For details about the APIs, see [@ohos.notificationManager](../reference/apis/js ```ts import notificationManager from '@ohos.notificationManager'; + import Base from '@ohos.base'; ``` 2. Call the API to request notification to be enabled. @@ -43,7 +44,7 @@ For details about the APIs, see [@ohos.notificationManager](../reference/apis/js ```ts notificationManager.requestEnableNotification().then(() => { console.info(`[ANS] requestEnableNotification success`); - }).catch((err) => { + }).catch((err:Base.BusinessError) => { console.error(`[ANS] requestEnableNotification failed, code is ${err.code}, message is ${err.message}`); }); ``` diff --git a/en/application-dev/notification/notification-subscription.md b/en/application-dev/notification/notification-subscription.md index 68bc11450b9302d66c05b3388ca8096e5c33088f..7e144d864cceb51035fa6095f989a97ac3c33f5c 100644 --- a/en/application-dev/notification/notification-subscription.md +++ b/en/application-dev/notification/notification-subscription.md @@ -40,31 +40,31 @@ The major APIs for notification subscription are described as follows. For detai ```ts import notificationSubscribe from '@ohos.notificationSubscribe'; + import Base from '@ohos.base'; ``` 3. Create a **subscriber** object. ```ts - let subscriber = { - onConsume: function (data) { + let subscriber:notificationSubscribe.NotificationSubscriber = { + onConsume: (data:notificationSubscribe.SubscribeCallbackData) => { let req = data.request; console.info(`onConsume callback. req.id: ${req.id}`); }, - onCancel: function (data) { + onCancel: (data:notificationSubscribe.SubscribeCallbackData) => { 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}`); + onUpdate: (data) => { + console.info(`onUpdate callback. req.id: ${req.sortedHashCode}`); }, - onConnect: function () { + onConnect: () => { console.info(`onConnect callback.}`); }, - onDisconnect: function () { + onDisconnect: () => { console.info(`onDisconnect callback.}`); }, - onDestroy: function () { + onDestroy: () => { console.info(`onDestroy callback.}`); }, }; @@ -73,11 +73,10 @@ The major APIs for notification subscription are described as follows. For detai 4. Initiate notification subscription. ```ts - notificationSubscribe.subscribe(subscriber, (err, data) => { // This API uses an asynchronous callback to return the result. + notificationSubscribe.subscribe(subscriber, (err:Base.BusinessError) => { // This API uses an asynchronous callback to return the result. if (err) { console.error(`Failed to subscribe notification. Code is ${err.code}, message is ${err.message}`); return; } - console.info(`Succeeded in subscribing to notification. Data: ${data}`); }); ``` diff --git a/en/application-dev/notification/notification-with-wantagent.md b/en/application-dev/notification/notification-with-wantagent.md index 3864db71c96b59827bdf4603f48199f27345a2a3..4a820360cc5f5f1c4ca829a629636dac0a672371 100644 --- a/en/application-dev/notification/notification-with-wantagent.md +++ b/en/application-dev/notification/notification-with-wantagent.md @@ -31,6 +31,8 @@ For details about the APIs, see [@ohos.app.ability.wantAgent](../reference/apis/ ```typescript import notificationManager from '@ohos.notificationManager'; import wantAgent from '@ohos.app.ability.wantAgent'; + import { WantAgent } from '@ohos.app.ability.wantAgent'; + import Base from '@ohos.base'; ``` 3. Create a **WantAgentInfo** object. @@ -38,10 +40,10 @@ For details about the APIs, see [@ohos.app.ability.wantAgent](../reference/apis/ Scenario 1: Create a [WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md) object for starting a UIAbility component. ```typescript - let wantAgentObj = null; // Save the WantAgent object created. It will be used to complete the trigger operations. + let wantAgentObj:WantAgent = null; // Save the WantAgent object created. It will be used to complete the trigger operations. // Set the action type through operationType of WantAgentInfo. - let wantAgentInfo = { + let wantAgentInfo:wantAgent.WantAgentInfo = { wants: [ { deviceId: '', @@ -62,10 +64,10 @@ For details about the APIs, see [@ohos.app.ability.wantAgent](../reference/apis/ Scenario 2: Create a [WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md) object for publishing a [common event](../application-models/common-event-overview.md). ```typescript - let wantAgentObj = null; // Save the WantAgent object created. It will be used to complete the trigger operations. + let wantAgentObj:WantAgent = null; // Save the WantAgent object created. It will be used to complete the trigger operations. // Set the action type through operationType of WantAgentInfo. - let wantAgentInfo = { + let wantAgentInfo:wantAgent.WantAgentInfo = { wants: [ { action: 'event_name', // Set the action name. @@ -82,7 +84,7 @@ For details about the APIs, see [@ohos.app.ability.wantAgent](../reference/apis/ ```typescript // Create a WantAgent object. - wantAgent.getWantAgent(wantAgentInfo, (err, data) => { + wantAgent.getWantAgent(wantAgentInfo, (err:Base.BusinessError, data:WantAgent) => { if (err) { console.error(`Failed to get want agent. Code is ${err.code}, message is ${err.message}`); return; @@ -110,7 +112,7 @@ For details about the APIs, see [@ohos.app.ability.wantAgent](../reference/apis/ wantAgent: wantAgentObj, } - notificationManager.publish(notificationRequest, (err) => { + notificationManager.publish(notificationRequest, (err:Base.BusinessError) => { if (err) { console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); return; diff --git a/en/application-dev/notification/progress-bar-notification.md b/en/application-dev/notification/progress-bar-notification.md index 4f016fefcbb6912fa9a0b998c7b5feb672503eee..86816dffa16895eb2022cc0b6fe54dd8e6c0458c 100644 --- a/en/application-dev/notification/progress-bar-notification.md +++ b/en/application-dev/notification/progress-bar-notification.md @@ -20,17 +20,18 @@ In the [NotificationTemplate](../reference/apis/js-apis-inner-notification-notif ```ts import notificationManager from '@ohos.notificationManager'; + import Base from '@ohos.base'; ``` 3. Check whether a specific template is supported. In this example, the template of the **downloadTemplate** type is checked. ```ts - notificationManager.isSupportTemplate('downloadTemplate').then((data) => { + notificationManager.isSupportTemplate('downloadTemplate').then((data:boolean) => { console.info(`[ANS] isSupportTemplate success`); console.info('Succeeded in supporting download template notification.'); let isSupportTpl: boolean = data; // The value true means that the template of the downloadTemplate type is supported, and false means the opposite. // ... - }).catch((err) => { + }).catch((err:Base.BusinessError) => { console.error(`Failed to support download template notification. Code is ${err.code}, message is ${err.message}`); }); ``` @@ -60,7 +61,7 @@ In the [NotificationTemplate](../reference/apis/js-apis-inner-notification-notif } // Publish the notification. - notificationManager.publish(notificationRequest, (err) => { + notificationManager.publish(notificationRequest, (err:Base.BusinessError) => { if (err) { console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); return; diff --git a/en/application-dev/notification/text-notification.md b/en/application-dev/notification/text-notification.md index fb1455e0dcdd791db6658935b48e90a6f14a3a14..88173e686faed92858b14f831d62ddd377ec708c 100644 --- a/en/application-dev/notification/text-notification.md +++ b/en/application-dev/notification/text-notification.md @@ -38,6 +38,7 @@ The following table describes the APIs for notification publishing. You specify ```ts import notificationManager from '@ohos.notificationManager'; + import Base from '@ohos.base'; ``` 3. Create a **NotificationRequest** object and publish a progress notification. @@ -56,7 +57,7 @@ The following table describes the APIs for notification publishing. You specify } }; - notificationManager.publish(notificationRequest, (err) => { + notificationManager.publish(notificationRequest, (err:Base.BusinessError) => { if (err) { console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); return; @@ -86,7 +87,7 @@ The following table describes the APIs for notification publishing. You specify }; // Publish the notification. - notificationManager.publish(notificationRequest, (err) => { + notificationManager.publish(notificationRequest, (err:Base.BusinessError) => { if (err) { console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); return; @@ -115,7 +116,7 @@ The following table describes the APIs for notification publishing. You specify }; // Publish the notification. - notificationManager.publish(notificationRequest, (err) => { + notificationManager.publish(notificationRequest, (err:Base.BusinessError) => { if (err) { console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); return; @@ -146,7 +147,7 @@ The following table describes the APIs for notification publishing. You specify }; // Publish the notification. - notificationManager.publish(notificationRequest, (err) => { + notificationManager.publish(notificationRequest, (err:Base.BusinessError) => { if (err) { console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); return; diff --git a/zh-cn/application-dev/notification/notification-badge.md b/zh-cn/application-dev/notification/notification-badge.md index a5b23055f2f75847836b0a927a9ab1f1cea60d77..4ce9b6e211ed7d7e6a3d68642e42c6cb9af4564b 100644 --- a/zh-cn/application-dev/notification/notification-badge.md +++ b/zh-cn/application-dev/notification/notification-badge.md @@ -28,6 +28,7 @@ ```ts import notificationManager from '@ohos.notificationManager'; + import Base from '@ohos.base'; ``` 2. 增加角标个数。 @@ -37,7 +38,7 @@ 示例为调用setBadgeNumber接口增加角标,在发布完新的通知后,调用该接口。 ```ts - function setBadgeNumberCallback(err) { + function setBadgeNumberCallback(err:Base.BusinessError) { if (err) { console.error(`Failed to set badge number. Code is ${err.code}, message is ${err.message}`); return; @@ -54,7 +55,7 @@ 一条通知被查看后,应用需要调用接口设置剩下未读通知个数,桌面刷新角标。 ```ts - function setBadgeNumberCallback(err) { + function setBadgeNumberCallback(err:Base.BusinessError) { if (err) { console.error(`Failed to set badge number. Code is ${err.code}, message is ${err.message}`); return; diff --git a/zh-cn/application-dev/notification/notification-enable.md b/zh-cn/application-dev/notification/notification-enable.md index 45d3345c19810f5e0c2dfce772cf1e9a378d8339..db75da44ec2104cc3ccf541d9aad6bf97aaff0ca 100644 --- a/zh-cn/application-dev/notification/notification-enable.md +++ b/zh-cn/application-dev/notification/notification-enable.md @@ -35,6 +35,7 @@ ```ts import notificationManager from '@ohos.notificationManager'; + import Base from '@ohos.base'; ``` 2. 请求发送通知的许可。 @@ -42,7 +43,7 @@ ```ts notificationManager.requestEnableNotification().then(() => { console.info(`[ANS] requestEnableNotification success`); - }).catch((err) => { + }).catch((err:Base.BusinessError) => { console.error(`[ANS] requestEnableNotification failed, code is ${err.code}, message is ${err.message}`); }); ``` diff --git a/zh-cn/application-dev/notification/notification-subscription.md b/zh-cn/application-dev/notification/notification-subscription.md index 33db2db09dc8ca0489f79ce12d6c2fff14789138..e1ad1fde6c81397408bfc44dfc774520388c23e6 100644 --- a/zh-cn/application-dev/notification/notification-subscription.md +++ b/zh-cn/application-dev/notification/notification-subscription.md @@ -40,31 +40,31 @@ ```ts import notificationSubscribe from '@ohos.notificationSubscribe'; + import Base from '@ohos.base'; ``` 3. 创建订阅者对象。 ```ts - let subscriber = { - onConsume: function (data) { + let subscriber:notificationSubscribe.NotificationSubscriber = { + onConsume: (data:notificationSubscribe.SubscribeCallbackData) => { let req = data.request; console.info(`onConsume callback. req.id: ${req.id}`); }, - onCancel: function (data) { + onCancel: (data:notificationSubscribe.SubscribeCallbackData) => { 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}`); + onUpdate: (data) => { + console.info(`onUpdate callback. req.id: ${req.sortedHashCode}`); }, - onConnect: function () { + onConnect: () => { console.info(`onConnect callback.}`); }, - onDisconnect: function () { + onDisconnect: () => { console.info(`onDisconnect callback.}`); }, - onDestroy: function () { + onDestroy: () => { console.info(`onDestroy callback.}`); }, }; @@ -73,11 +73,10 @@ 4. 发起通知订阅。 ```ts - notificationSubscribe.subscribe(subscriber, (err, data) => { // callback形式调用异步接口 + notificationSubscribe.subscribe(subscriber, (err:Base.BusinessError) => { // callback形式调用异步接口 if (err) { console.error(`Failed to subscribe notification. Code is ${err.code}, message is ${err.message}`); return; } - 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 4b3a00ff7ceefb580ba2b6e1aff051ea95f45c93..3cc82b5c38e202d22321874b1b31034fa43ae324 100644 --- a/zh-cn/application-dev/notification/notification-with-wantagent.md +++ b/zh-cn/application-dev/notification/notification-with-wantagent.md @@ -30,6 +30,8 @@ ```typescript import notificationManager from '@ohos.notificationManager'; import wantAgent from '@ohos.app.ability.wantAgent'; + import { WantAgent } from '@ohos.app.ability.wantAgent'; + import Base from '@ohos.base'; ``` 3. 创建WantAgentInfo信息。 @@ -37,10 +39,10 @@ 场景一:创建拉起UIAbility的WantAgent的[WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md)信息。 ```typescript - let wantAgentObj = null; // 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。 + let wantAgentObj:WantAgent = null; // 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。 // 通过WantAgentInfo的operationType设置动作类型 - let wantAgentInfo = { + let wantAgentInfo:wantAgent.WantAgentInfo = { wants: [ { deviceId: '', @@ -61,10 +63,10 @@ 场景二:创建发布[公共事件](../application-models/common-event-overview.md)的WantAgent的[WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md)信息。 ```typescript - let wantAgentObj = null; // 用于保存创建成功的WantAgent对象,后续使用其完成触发的动作。 + let wantAgentObj:WantAgent = null; // 用于保存创建成功的WantAgent对象,后续使用其完成触发的动作。 // 通过WantAgentInfo的operationType设置动作类型 - let wantAgentInfo = { + let wantAgentInfo:wantAgent.WantAgentInfo = { wants: [ { action: 'event_name', // 设置事件名 @@ -81,7 +83,7 @@ ```typescript // 创建WantAgent - wantAgent.getWantAgent(wantAgentInfo, (err, data) => { + wantAgent.getWantAgent(wantAgentInfo, (err:Base.BusinessError, data:WantAgent) => { if (err) { console.error(`Failed to get want agent. Code is ${err.code}, message is ${err.message}`); return; @@ -109,7 +111,7 @@ wantAgent: wantAgentObj, } - notificationManager.publish(notificationRequest, (err) => { + notificationManager.publish(notificationRequest, (err:Base.BusinessError) => { if (err) { console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); return; diff --git a/zh-cn/application-dev/notification/progress-bar-notification.md b/zh-cn/application-dev/notification/progress-bar-notification.md index d5720422d429fea4edf5f0da01309ac4127ecdf2..00a523b1879558819e518c1cc07e893ef056c889 100644 --- a/zh-cn/application-dev/notification/progress-bar-notification.md +++ b/zh-cn/application-dev/notification/progress-bar-notification.md @@ -26,17 +26,18 @@ ```ts import notificationManager from '@ohos.notificationManager'; + import Base from '@ohos.base'; ``` 3. 查询系统是否支持进度条模板,查询结果为支持downloadTemplate模板类通知。 ```ts - notificationManager.isSupportTemplate('downloadTemplate').then((data) => { + notificationManager.isSupportTemplate('downloadTemplate').then((data:boolean) => { console.info(`[ANS] isSupportTemplate success`); console.info('Succeeded in supporting download template notification.'); let isSupportTpl: boolean = data; // isSupportTpl的值为true表示支持支持downloadTemplate模板类通知,false表示不支持 // ... - }).catch((err) => { + }).catch((err:Base.BusinessError) => { console.error(`Failed to support download template notification. Code is ${err.code}, message is ${err.message}`); }); ``` @@ -65,7 +66,7 @@ } // 发布通知 - notificationManager.publish(notificationRequest, (err) => { + notificationManager.publish(notificationRequest, (err:Base.BusinessError) => { if (err) { console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); return; diff --git a/zh-cn/application-dev/notification/text-notification.md b/zh-cn/application-dev/notification/text-notification.md index 7685eecf65bb5030d7c2615d57f8c91e0d9713b2..34e8924f0f501762e00eed13cdc2ad0b2e0d3a7a 100644 --- a/zh-cn/application-dev/notification/text-notification.md +++ b/zh-cn/application-dev/notification/text-notification.md @@ -37,6 +37,7 @@ ```ts import notificationManager from '@ohos.notificationManager'; + import Base from '@ohos.base'; ``` 3. 构造NotificationRequest对象,并发布通知。 @@ -55,7 +56,7 @@ } }; - notificationManager.publish(notificationRequest, (err) => { + notificationManager.publish(notificationRequest, (err:Base.BusinessError) => { if (err) { console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); return; @@ -85,7 +86,7 @@ }; // 发布通知 - notificationManager.publish(notificationRequest, (err) => { + notificationManager.publish(notificationRequest, (err:Base.BusinessError) => { if (err) { console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); return; @@ -114,7 +115,7 @@ }; // 发布通知 - notificationManager.publish(notificationRequest, (err) => { + notificationManager.publish(notificationRequest, (err:Base.BusinessError) => { if (err) { console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); return; @@ -145,7 +146,7 @@ }; // 发布通知 - notificationManager.publish(notificationRequest, (err) => { + notificationManager.publish(notificationRequest, (err:Base.BusinessError) => { if (err) { console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`); return;