未验证 提交 a465b566 编写于 作者: O openharmony_ci 提交者: Gitee

!18970 翻译完成 18418

Merge pull request !18970 from ester.zhou/TR-18043
# Enabling Notification
To publish a notification, you must have notification enabled for your application. You can call the [requestEnableNotification()](../reference/apis/js-apis-notificationManager.md#notificationrequestenablenotification) API to display a dialog box prompting the user to enable notification for your application. Note that the dialog box is displayed only when the API is called for the first time.
To publish a notification, you must have notification enabled for your application. You can call the [requestEnableNotification()](../reference/apis/js-apis-notificationManager.md#notificationmanagerrequestenablenotification) API to display a dialog box prompting the user to enable notification for your application. Note that the dialog box is displayed only when the API is called for the first time.
**Figure 1** Dialog box prompting the user to enable notification
**Figure 1** Dialog box prompting the user to enable notification
![en-us_image_0000001416585590](figures/en-us_image_0000001416585590.png)
- Touching **allow** enables notification for the application, and touching **ban** keeps notification disabled.
- The dialog box will not be displayed again when [requestEnableNotification()](../reference/apis/js-apis-notificationManager.md#notificationrequestenablenotification) is called later. The user can manually enable notification as follows.
- The dialog box will not be displayed again when [requestEnableNotification()](../reference/apis/js-apis-notificationManager.md#notificationmanagerrequestenablenotification) is called later. The user can manually enable notification as follows.
| 1. Swipe down from the upper left corner of the device screen to access the notification panel. | 2. Touch the **Settings** icon in the upper right corner. On the notification screen, locate the target application.| 3. Toggle on **Allow notifications**. |
| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
......@@ -19,7 +19,7 @@ To publish a notification, you must have notification enabled for your applicati
## Available APIs
For details about the APIs, see [@ohos.notificationManager](../reference/apis/js-apis-notificationManager.md#notificationrequestenablenotification).
For details about the APIs, see [@ohos.notificationManager](../reference/apis/js-apis-notificationManager.md#notificationmanagerrequestenablenotification).
**Table 1** Notification APIs
......
......@@ -24,4 +24,5 @@ A notification is generated by the notification sender and sent to the notificat
System applications also support notification-related configuration options, such as switches. The system configuration initiates a configuration request and sends the request to the notification subsystem for storage in the memory and database.
**Figure 1** Notification service process
![en-us_image_0000001466582017](figures/en-us_image_0000001466582017.png)
......@@ -48,23 +48,24 @@ The major APIs for notification subscription are described as follows. For detai
let subscriber = {
onConsume: function (data) {
let req = data.request;
console.info('[ANS] onConsume callback req.id: ' + req.id);
console.info(`onConsume callback. req.id: ${req.id}`);
},
onCancel: function (data) {
let req = data.request;
console.info('[ANS] onCancel callback req.id: : ' + req.id);
console.info(`onCancel callback. req.id: ${req.id}`);
},
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');
console.info(`onConnect callback.}`);
},
onDisconnect: function () {
console.info('[ANS] onDisConnect in test');
console.info(`onDisconnect callback.}`);
},
onDestroy: function () {
console.info('[ANS] onDestroy in test');
console.info(`onDestroy callback.}`);
},
};
```
......@@ -74,9 +75,9 @@ The major APIs for notification subscription are described as follows. For detai
```ts
notificationSubscribe.subscribe(subscriber, (err, data) => { // This API uses an asynchronous callback to return the result.
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}`);
});
```
......@@ -4,7 +4,7 @@ A [WantAgent](../reference/apis/js-apis-app-ability-wantAgent.md) object encapsu
Below you can see the process of adding a **WantAgent** object to a notification. The notification publisher requests a **WantAgent** object from the Ability Manager Service (AMS), and then sends a notification carrying the **WantAgent** object to the home screen. When the user touches the notification from the notification panel on the home screen, the **WantAgent** object is triggered.
**Figure 1** Publishing a notification with a WantAgent object
**Figure 1** Publishing a notification with a WantAgent object
![notification-with-wantagent](figures/notification-with-wantagent.png)
......@@ -15,11 +15,11 @@ For details about the APIs, see [@ohos.app.ability.wantAgent](../reference/apis/
| Name| Description|
| -------- | -------- |
|getWantAgent(info: WantAgentInfo, callback: AsyncCallback<WantAgent>): void | Creates a **WantAgent** object.|
|trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback<CompleteData>): void | Triggers a **WantAgent** object.|
|cancel(agent: WantAgent, callback: AsyncCallback<void>): void | Cancels a **WantAgent** object.|
|getWant(agent: WantAgent, callback: AsyncCallback<Want>): void | Obtains a **WantAgent** object.|
|equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback<boolean>): void | Checks whether two **WantAgent** objects are equal.|
| getWantAgent(info: WantAgentInfo, callback: AsyncCallback<WantAgent>): void | Creates a **WantAgent** object.|
| trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback<CompleteData>): void | Triggers a **WantAgent** object.|
| cancel(agent: WantAgent, callback: AsyncCallback<void>): void | Cancels a **WantAgent** object.|
| getWant(agent: WantAgent, callback: AsyncCallback<Want>): void | Obtains a **WantAgent** object.|
| equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback<boolean>): void | Checks whether two **WantAgent** objects are equal.|
## How to Develop
......@@ -75,7 +75,7 @@ For details about the APIs, see [@ohos.app.ability.wantAgent](../reference/apis/
operationType: wantAgent.OperationType.SEND_COMMON_EVENT,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.CONSTANT_FLAG],
}
};
```
4. Invoke the [getWantAgent()](../reference/apis/js-apis-app-ability-wantAgent.md#wantagentgetwantagent) API to create a **WantAgent** object.
......@@ -84,10 +84,10 @@ For details about the APIs, see [@ohos.app.ability.wantAgent](../reference/apis/
// Create a WantAgent object.
wantAgent.getWantAgent(wantAgentInfo, (err, data) => {
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}`);
return;
}
console.info('[WantAgent]getWantAgent success');
console.info('Succeeded in geting want agent.');
wantAgentObj = data;
});
```
......@@ -112,10 +112,10 @@ For details about the APIs, see [@ohos.app.ability.wantAgent](../reference/apis/
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.');
});
```
......
......@@ -27,10 +27,11 @@ In the [NotificationTemplate](../reference/apis/js-apis-inner-notification-notif
```ts
notificationManager.isSupportTemplate('downloadTemplate').then((data) => {
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) => {
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}`);
});
```
......@@ -61,9 +62,9 @@ In the [NotificationTemplate](../reference/apis/js-apis-inner-notification-notif
// Publish the notification.
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.');
});
```
......@@ -3,8 +3,7 @@
You can publish basic notifications to send SMS messages, prompt messages, and advertisements. Available content types of basic notifications include normal text, long text, multi-line text, and picture-attached.
**Table 1** Basic notification content types
**Table 1** Basic notification content types
| Type| Description|
| -------- | -------- |
......@@ -13,16 +12,16 @@ You can publish basic notifications to send SMS messages, prompt messages, and a
| NOTIFICATION_CONTENT_MULTILINE | Multi-line text notification.|
| NOTIFICATION_CONTENT_PICTURE | Picture-attached notification.|
Notifications are displayed in the notification panel, which is the only system subscriber to notifications. Below you can see two examples of the basic notification.
Notifications are displayed in the notification panel, which is the only supported subscriber to notifications. Below you can see two examples of the basic notification.
**Figure 1** Examples of the basic notification
![en-us_image_0000001466462305](figures/en-us_image_0000001466462305.png)
## Available APIs
The following table describes the APIs for notification publishing. You specify the notification type by setting the [NotificationRequest](../reference/apis/js-apis-notificationManager.md#notificationrequest) parameter in the APIs.
The following table describes the APIs for notification publishing. You specify the notification type by setting the [NotificationRequest](../reference/apis/js-apis-inner-notification-notificationRequest.md#notificationrequest) parameter in the APIs.
| Name| Description|
| -------- | -------- |
......@@ -55,14 +54,14 @@ The following table describes the APIs for notification publishing. You specify
additionalText: 'test_additionalText',
}
}
}
};
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.');
});
```
......@@ -84,15 +83,15 @@ The following table describes the APIs for notification publishing. You specify
expandedTitle: 'test_expandedTitle',
}
}
}
};
// Publish the notification.
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.');
});
```
......@@ -113,15 +112,15 @@ The following table describes the APIs for notification publishing. You specify
lines: ['line_01', 'line_02', 'line_03', 'line_04'],
}
}
}
};
// Publish the notification.
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.');
});
```
......@@ -144,15 +143,15 @@ The following table describes the APIs for notification publishing. You specify
picture: imagePixelMap
}
}
}
};
// Publish the notification.
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.');
});
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册