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

!13494 翻译完成 12832+12653+12413+13291+13268

Merge pull request !13494 from ester.zhou/C2-0111
# CommonEvent # @ohos.commonEvent
The **CommonEvent** module provides common event capabilities, including the capabilities to publish, subscribe to, and unsubscribe from common events, as well obtaining and setting the common event result code and result data. The **CommonEvent** module provides common event capabilities, including the capabilities to publish, subscribe to, and unsubscribe from common events, as well obtaining and setting the common event result code and result data.
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The APIs provided by this module are no longer maintained since API version 9. You are advised to use [@ohos.commonEventManager](js-apis-commonEventManager.md).
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -14,7 +15,7 @@ import CommonEvent from '@ohos.commonEvent'; ...@@ -14,7 +15,7 @@ import CommonEvent from '@ohos.commonEvent';
## Support ## Support
Provides the event types supported by the **CommonEvent** module. The name and value indicate the macro and name of a common event, respectively. The table below lists the event types supported by the **CommonEvent** module. The name and value indicate the macro and name of a common event, respectively.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
...@@ -167,8 +168,8 @@ Provides the event types supported by the **CommonEvent** module. The name and v ...@@ -167,8 +168,8 @@ Provides the event types supported by the **CommonEvent** module. The name and v
| COMMON_EVENT_ACCOUNT_DELETED | usual.event.data.ACCOUNT_DELETED | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS | Indicates the common event that the account was deleted. | | COMMON_EVENT_ACCOUNT_DELETED | usual.event.data.ACCOUNT_DELETED | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS | Indicates the common event that the account was deleted. |
| COMMON_EVENT_FOUNDATION_READY | usual.event.data.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the foundation is ready. | | COMMON_EVENT_FOUNDATION_READY | usual.event.data.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED | Indicates the common event that the foundation is ready. |
| COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | - | Indicates the common event that the airplane mode of the device has changed. | | COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | - | Indicates the common event that the airplane mode of the device has changed. |
| COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup> | usual.event.SPLIT_SCREEN | - | Indicates the common event of screen splitting. | | COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup> | usual.event.SPLIT_SCREEN | - | Indicates the common event of screen splitting. |
| COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | Indicates the common event that the notification slot has changed. | | COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | Indicates the common event that the notification slot has been updated. |
| COMMON_EVENT_SPN_INFO_CHANGED <sup>9+<sup> | usual.event.SPN_INFO_CHANGED | - | Indicates the common event that the SPN displayed has been updated. | | COMMON_EVENT_SPN_INFO_CHANGED <sup>9+<sup> | usual.event.SPN_INFO_CHANGED | - | Indicates the common event that the SPN displayed has been updated. |
| COMMON_EVENT_QUICK_FIX_APPLY_RESULT <sup>9+<sup> | usual.event.QUICK_FIX_APPLY_RESULT | - | Indicates the common event that a quick fix is applied to the application. | | COMMON_EVENT_QUICK_FIX_APPLY_RESULT <sup>9+<sup> | usual.event.QUICK_FIX_APPLY_RESULT | - | Indicates the common event that a quick fix is applied to the application. |
...@@ -192,7 +193,7 @@ Publishes a common event. This API uses an asynchronous callback to return the r ...@@ -192,7 +193,7 @@ Publishes a common event. This API uses an asynchronous callback to return the r
```js ```js
// Callback for common event publication // Callback for common event publication
function PublishCallBack(err) { function publishCallBack(err) {
if (err.code) { if (err.code) {
console.error("publish failed " + JSON.stringify(err)); console.error("publish failed " + JSON.stringify(err));
} else { } else {
...@@ -201,7 +202,7 @@ function PublishCallBack(err) { ...@@ -201,7 +202,7 @@ function PublishCallBack(err) {
} }
// Publish a common event. // Publish a common event.
CommonEvent.publish("event", PublishCallBack); CommonEvent.publish("event", publishCallBack);
``` ```
...@@ -229,12 +230,12 @@ Publishes a common event with given attributes. This API uses an asynchronous ca ...@@ -229,12 +230,12 @@ Publishes a common event with given attributes. This API uses an asynchronous ca
// Attributes of a common event. // Attributes of a common event.
let options = { let options = {
code: 0, // Result code of the common event. code: 0, // Result code of the common event.
data: "initial data";// Result data of the common event. data: "initial data",// Result data of the common event.
isOrdered: true // The common event is an ordered one. isOrdered: true // The common event is an ordered one.
} }
// Callback for common event publication // Callback for common event publication
function PublishCallBack(err) { function publishCallBack(err) {
if (err.code) { if (err.code) {
console.error("publish failed " + JSON.stringify(err)); console.error("publish failed " + JSON.stringify(err));
} else { } else {
...@@ -243,7 +244,7 @@ function PublishCallBack(err) { ...@@ -243,7 +244,7 @@ function PublishCallBack(err) {
} }
// Publish a common event. // Publish a common event.
CommonEvent.publish("event", options, PublishCallBack); CommonEvent.publish("event", options, publishCallBack);
``` ```
...@@ -270,7 +271,7 @@ Publishes a common event to a specific user. This API uses an asynchronous callb ...@@ -270,7 +271,7 @@ Publishes a common event to a specific user. This API uses an asynchronous callb
```js ```js
// Callback for common event publication // Callback for common event publication
function PublishAsUserCallBack(err) { function publishAsUserCallBack(err) {
if (err.code) { if (err.code) {
console.error("publishAsUser failed " + JSON.stringify(err)); console.error("publishAsUser failed " + JSON.stringify(err));
} else { } else {
...@@ -282,7 +283,7 @@ function PublishAsUserCallBack(err) { ...@@ -282,7 +283,7 @@ function PublishAsUserCallBack(err) {
let userId = 100; let userId = 100;
// Publish a common event. // Publish a common event.
CommonEvent.publishAsUser("event", userId, PublishAsUserCallBack); CommonEvent.publishAsUser("event", userId, publishAsUserCallBack);
``` ```
...@@ -313,11 +314,11 @@ Publishes a common event with given attributes to a specific user. This API uses ...@@ -313,11 +314,11 @@ Publishes a common event with given attributes to a specific user. This API uses
// Attributes of a common event. // Attributes of a common event.
let options = { let options = {
code: 0, // Result code of the common event. code: 0, // Result code of the common event.
data: "initial data";// Result data of the common event. data: "initial data",// Result data of the common event.
} }
// Callback for common event publication // Callback for common event publication
function PublishAsUserCallBack(err) { function publishAsUserCallBack(err) {
if (err.code) { if (err.code) {
console.error("publishAsUser failed " + JSON.stringify(err)); console.error("publishAsUser failed " + JSON.stringify(err));
} else { } else {
...@@ -329,7 +330,7 @@ function PublishAsUserCallBack(err) { ...@@ -329,7 +330,7 @@ function PublishAsUserCallBack(err) {
let userId = 100; let userId = 100;
// Publish a common event. // Publish a common event.
CommonEvent.publishAsUser("event", userId, options, PublishAsUserCallBack); CommonEvent.publishAsUser("event", userId, options, publishAsUserCallBack);
``` ```
...@@ -361,7 +362,7 @@ let subscribeInfo = { ...@@ -361,7 +362,7 @@ let subscribeInfo = {
}; };
// Callback for subscriber creation. // Callback for subscriber creation.
function CreateSubscriberCallBack(err, commonEventSubscriber) { function createSubscriberCallBack(err, commonEventSubscriber) {
if (err.code) { if (err.code) {
console.error("createSubscriber failed " + JSON.stringify(err)); console.error("createSubscriber failed " + JSON.stringify(err));
} else { } else {
...@@ -371,7 +372,7 @@ function CreateSubscriberCallBack(err, commonEventSubscriber) { ...@@ -371,7 +372,7 @@ function CreateSubscriberCallBack(err, commonEventSubscriber) {
} }
// Create a subscriber. // Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); CommonEvent.createSubscriber(subscribeInfo, createSubscriberCallBack);
``` ```
...@@ -442,7 +443,7 @@ let subscribeInfo = { ...@@ -442,7 +443,7 @@ let subscribeInfo = {
}; };
// Callback for common event subscription. // Callback for common event subscription.
function SubscribeCallBack(err, data) { function subscribeCallBack(err, data) {
if (err.code) { if (err.code) {
console.error("subscribe failed " + JSON.stringify(err)); console.error("subscribe failed " + JSON.stringify(err));
} else { } else {
...@@ -451,19 +452,19 @@ function SubscribeCallBack(err, data) { ...@@ -451,19 +452,19 @@ function SubscribeCallBack(err, data) {
} }
// Callback for subscriber creation. // Callback for subscriber creation.
function CreateSubscriberCallBack(err, commonEventSubscriber) { function createSubscriberCallBack(err, commonEventSubscriber) {
if (err.code) { if (err.code) {
console.error("createSubscriber failed " + JSON.stringify(err)); console.error("createSubscriber failed " + JSON.stringify(err));
} else { } else {
console.info("createSubscriber"); console.info("createSubscriber");
subscriber = commonEventSubscriber; subscriber = commonEventSubscriber;
// Subscribe to a common event. // Subscribe to a common event.
CommonEvent.subscribe(subscriber, SubscribeCallBack); CommonEvent.subscribe(subscriber, subscribeCallBack);
} }
} }
// Create a subscriber. // Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); CommonEvent.createSubscriber(subscribeInfo, createSubscriberCallBack);
``` ```
...@@ -494,7 +495,7 @@ let subscribeInfo = { ...@@ -494,7 +495,7 @@ let subscribeInfo = {
}; };
// Callback for common event subscription. // Callback for common event subscription.
function SubscribeCallBack(err, data) { function subscribeCallBack(err, data) {
if (err.code) { if (err.code) {
console.info("subscribe failed " + JSON.stringify(err)); console.info("subscribe failed " + JSON.stringify(err));
} else { } else {
...@@ -503,19 +504,19 @@ function SubscribeCallBack(err, data) { ...@@ -503,19 +504,19 @@ function SubscribeCallBack(err, data) {
} }
// Callback for subscriber creation. // Callback for subscriber creation.
function CreateSubscriberCallBack(err, commonEventSubscriber) { function createSubscriberCallBack(err, commonEventSubscriber) {
if (err.code) { if (err.code) {
console.info("createSubscriber failed " + JSON.stringify(err)); console.info("createSubscriber failed " + JSON.stringify(err));
} else { } else {
console.info("createSubscriber"); console.info("createSubscriber");
subscriber = commonEventSubscriber; subscriber = commonEventSubscriber;
// Subscribe to a common event. // Subscribe to a common event.
CommonEvent.subscribe(subscriber, SubscribeCallBack); CommonEvent.subscribe(subscriber, subscribeCallBack);
} }
} }
// Callback for common event unsubscription. // Callback for common event unsubscription.
function UnsubscribeCallBack(err) { function unsubscribeCallBack(err) {
if (err.code) { if (err.code) {
console.info("unsubscribe failed " + JSON.stringify(err)); console.info("unsubscribe failed " + JSON.stringify(err));
} else { } else {
...@@ -524,10 +525,10 @@ function UnsubscribeCallBack(err) { ...@@ -524,10 +525,10 @@ function UnsubscribeCallBack(err) {
} }
// Create a subscriber. // Create a subscriber.
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); CommonEvent.createSubscriber(subscribeInfo, createSubscriberCallBack);
// Unsubscribe from the common event. // Unsubscribe from the common event.
CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack); CommonEvent.unsubscribe(subscriber, unsubscribeCallBack);
``` ```
## CommonEventSubscriber ## CommonEventSubscriber
...@@ -841,7 +842,6 @@ isOrderedCommonEvent(callback: AsyncCallback\<boolean>): void ...@@ -841,7 +842,6 @@ isOrderedCommonEvent(callback: AsyncCallback\<boolean>): void
Checks whether this common event is an ordered one. This API uses an asynchronous callback to return the result. Checks whether this common event is an ordered one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
**Parameters** **Parameters**
...@@ -872,7 +872,6 @@ isOrderedCommonEvent(): Promise\<boolean> ...@@ -872,7 +872,6 @@ isOrderedCommonEvent(): Promise\<boolean>
Checks whether this common event is an ordered one. This API uses a promise to return the result. Checks whether this common event is an ordered one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
**Return value** **Return value**
...@@ -899,7 +898,6 @@ isStickyCommonEvent(callback: AsyncCallback\<boolean>): void ...@@ -899,7 +898,6 @@ isStickyCommonEvent(callback: AsyncCallback\<boolean>): void
Checks whether this common event is a sticky one. This API uses an asynchronous callback to return the result. Checks whether this common event is a sticky one. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
**Parameters** **Parameters**
...@@ -930,7 +928,6 @@ isStickyCommonEvent(): Promise\<boolean> ...@@ -930,7 +928,6 @@ isStickyCommonEvent(): Promise\<boolean>
Checks whether this common event is a sticky one. This API uses a promise to return the result. Checks whether this common event is a sticky one. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
**Return value** **Return value**
...@@ -1233,39 +1230,45 @@ subscriber.finishCommonEvent().then(() => { ...@@ -1233,39 +1230,45 @@ subscriber.finishCommonEvent().then(() => {
## CommonEventData ## CommonEventData
Describes the common event data body.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
| Name | Readable| Writable| Type | Description | | Name | Type | Readable| Writable| Description |
| ---------- | ---- | ---- | -------------------- | ------------------------------------------------------- | | ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- |
| event | Yes | No | string | Name of the common event that is being received. | | event | string | Yes | No | Name of the common event that is being received. |
| bundleName | Yes | No | string | Bundle name. | | bundleName | string | Yes | No | Bundle name. |
| code | Yes | No | number | Result code of the common event, which is used to transfer data of the int type. | | code | number | Yes | No | Result code of the common event, which is used to transfer data of the int type. |
| data | Yes | No | string | Custom result data of the common event, which is used to transfer data of the string type.| | data | string | Yes | No | Custom result data of the common event, which is used to transfer data of the string type.|
| parameters | Yes | No | {[key: string]: any} | Additional information about the common event. | | parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
## CommonEventPublishData ## CommonEventPublishData
Describes the data body published by a common event, including the common event content and attributes.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
| Name | Readable| Writable| Type | Description | | Name | Type | Readable| Writable| Description |
| --------------------- | ---- | ---- | -------------------- | ---------------------------- | | --------------------- | -------------------- | ---- | ---- | ---------------------------- |
| bundleName | Yes | No | string | Bundle name. | | bundleName | string | Yes | No | Bundle name. |
| code | Yes | No | number | Result code of the common event. | | code | number | Yes | No | Result code of the common event. |
| data | Yes | No | string | Custom result data of the common event.| | data | string | Yes | No | Custom result data of the common event.|
| subscriberPermissions | Yes | No | Array\<string> | Permissions required for subscribers to receive the common event. | | subscriberPermissions | Array\<string> | Yes | No | Permissions required for subscribers to receive the common event. |
| isOrdered | Yes | No | boolean | Whether the common event is an ordered one. | | isOrdered | boolean | Yes | No | Whether the common event is an ordered one. |
| isSticky | Yes | No | boolean | Whether the common event is a sticky one. | | isSticky | boolean | Yes | No | Whether the common event is a sticky one. Only system applications and system services are allowed to send sticky events.|
| parameters | Yes | No | {[key: string]: any} | Additional information about the common event. | | parameters | {[key: string]: any} | Yes | No | Additional information about the common event. |
## CommonEventSubscribeInfo ## CommonEventSubscribeInfo
Provides the subscriber information.
**System capability**: SystemCapability.Notification.CommonEvent **System capability**: SystemCapability.Notification.CommonEvent
| Name | Readable| Writable| Type | Description | | Name | Type | Readable| Writable| Description |
| ------------------- | ---- | ---- | -------------- | ------------------------------------------------------------ | | ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| events | Yes | No | Array\<string> | Name of the common event to publish. | | events | Array\<string> | Yes | No | Name of the common event to publish. |
| publisherPermission | Yes | No | string | Permissions required for publishers to publish the common event. | | publisherPermission | string | Yes | No | Permissions required for publishers to publish the common event. |
| publisherDeviceId | Yes | No | string | Device ID. The value must be the ID of an existing device on the same network. | | publisherDeviceId | string | Yes | No | Device ID. The value must be the ID of an existing device on the same network. |
| userId | Yes | No | number | User ID. The default value is the ID of the current user. If this parameter is specified, the value must be an existing user ID in the system.| | userId | number | Yes | No | User ID. The default value is the ID of the current user. If this parameter is specified, the value must be an existing user ID in the system.|
| priority | Yes | No | number | Subscriber priority. The value ranges from -100 to 1000. | | priority | number | Yes | No | Subscriber priority. The value ranges from -100 to +1000. |
...@@ -804,7 +804,7 @@ router.replace({ ...@@ -804,7 +804,7 @@ router.replace({
}); });
``` ```
## router.replace<sup>(deprecated)</sup> ## router.replace<sup>(deprecated)</sup>
replace(options: RouterOptions, mode: RouterMode): void replace(options: RouterOptions, mode: RouterMode): void
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册