@@ -13,14 +13,14 @@ Each application can subscribe to common events as required. After your applicat
...
@@ -13,14 +13,14 @@ Each application can subscribe to common events as required. After your applicat
## Common Event Subscription Development
## Common Event Subscription Development
### When to Use
### When to Use
You can create a subscriber object to subscribe to a common event to obtain the parameters passed in the event. Certain system common events require specific permissions to subscribe to. For details, see [Required Permissions](../reference/apis/js-apis-commonEvent.md).
You can create a subscriber object to subscribe to a common event to obtain the parameters passed in the event. Certain system common events require specific permissions to subscribe to. For details, see [Required Permissions](../reference/apis/js-apis-commonEvent.md#support).
| commonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback) | Creates a subscriber. This API uses a callback to return the result.|
| createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback) | Creates a subscriber. This API uses a callback to return the result.|
| commonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo) | Creates a subscriber. This API uses a promise to return the result. |
| createSubscriber(subscribeInfo: CommonEventSubscribeInfo) | Creates a subscriber. This API uses a promise to return the result. |
| commonEvent.subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback) | Subscribes to common events.|
| subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback) | Subscribes to common events.|
### How to Develop
### How to Develop
1. Import the **commonEvent** module.
1. Import the **commonEvent** module.
...
@@ -82,8 +82,8 @@ You can use the **publish** APIs to publish a custom common event, which can car
...
@@ -82,8 +82,8 @@ You can use the **publish** APIs to publish a custom common event, which can car
### Available APIs
### Available APIs
| API | Description|
| API | Description|
| ---------------------------------- | ------ |
| ---------------------------------- | ------ |
| commonEvent.publish(event: string, callback: AsyncCallback) | Publishes a common event.|
| publish(event: string, callback: AsyncCallback) | Publishes a common event.|
| commonEvent.publish(event: string, options: CommonEventPublishData, callback: AsyncCallback) | Publishes a common event with given attributes.|
| publish(event: string, options: CommonEventPublishData, callback: AsyncCallback) | Publishes a common event with given attributes.|
### How to Develop
### How to Develop
#### Development for Publishing a Common Event
#### Development for Publishing a Common Event
...
@@ -119,7 +119,7 @@ import commonEvent from '@ohos.commonEvent'
...
@@ -119,7 +119,7 @@ import commonEvent from '@ohos.commonEvent'
// Attributes of a common event.
// Attributes of a common event.
varoptions={
varoptions={
code:1,// Result code of the common event
code:1,// Result code of the common event
data:"initial data",// Result data of the common event
data:"initial data";// Result data of the common event
}
}
```
```
...
@@ -144,7 +144,7 @@ You can use the **unsubscribe** API to unsubscribe from a common event.
...
@@ -144,7 +144,7 @@ You can use the **unsubscribe** API to unsubscribe from a common event.
### Available APIs
### Available APIs
| API | Description|
| API | Description|
| ---------------------------------- | ------ |
| ---------------------------------- | ------ |
| commonEvent.unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback) | Unsubscribes from a common event.|
| unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback) | Unsubscribes from a common event.|
### How to Develop
### How to Develop
1. Import the **commonEvent** module.
1. Import the **commonEvent** module.
...
@@ -153,7 +153,7 @@ You can use the **unsubscribe** API to unsubscribe from a common event.
...
@@ -153,7 +153,7 @@ You can use the **unsubscribe** API to unsubscribe from a common event.
importcommonEventfrom'@ohos.commonEvent';
importcommonEventfrom'@ohos.commonEvent';
```
```
2. Subscribe to a common event by following instructions in [Common Event Subscription Development](#Common-Event-Subscription-Development).
2. Subscribe to a common event by following instructions in [Common Event Subscription Development](#common-event-subscription-development).
3. Invoke the **unsubscribe** API in **CommonEvent** to unsubscribe from the common event.
3. Invoke the **unsubscribe** API in **CommonEvent** to unsubscribe from the common event.
@@ -7,16 +7,13 @@ Common Event Service (CES) enables applications to publish, subscribe to, and un
...
@@ -7,16 +7,13 @@ Common Event Service (CES) enables applications to publish, subscribe to, and un
![ces](figures/ces.png)
![ces](figures/ces.png)
- System common event: sent by the system based on system policies to the applications that have subscribed to the event. This type of event includes the screen-on/off events that the users are aware of and the system events published by key system services, such as USB device attachment or detachment, network connection, and system update events.
- System common event: sent by the system based on system policies to the applications that have subscribed to the event. This type of event includes the screen-on/off events that the users are aware of and the system events published by key system services, such as USB device attachment or detachment, network connection, and system update events.
- Custom common event: customized by applications to be received by specific subscribers. This type of event is usually related to the service logic of the sender applications.
- Custom common event: customized by applications to be received by specific subscribers. This type of event is usually related to the service logic of the sender applications.
The Advanced Notification Service (ANS) enables applications to publish notifications. Below are some typical use cases for publishing notifications:
The Advanced Notification Service (ANS) enables applications to publish notifications. Below are some typical use cases for publishing notifications:
- Display received SMS messages and instant messages.
- Display received SMS messages and instant messages.
- Display push messages of applications, such as advertisements, version updates, and news notifications.
- Display push messages of applications, such as advertisements, version updates, and news notifications.
- Display ongoing events, such as music playback, navigation information, and download progress.
- Display ongoing events, such as music playback, navigation information, and download progress.
Notifications are displayed in the notification panel. Uses can delete a notification or click the notification to trigger predefined actions.
Notifications are displayed in the notification panel. Uses can delete a notification or click the notification to trigger predefined actions.