提交 47ff1bfe 编写于 作者: X XKK

适配ArkTs

Signed-off-by: NXKK <huyingsong@huawei.com>
上级 c1f20a4b
......@@ -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;
......
......@@ -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}`);
});
```
......@@ -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}`);
});
```
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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}`);
});
```
......
......@@ -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}`);
});
```
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册