已合并
update docs #154911
LexieLi创建于 7月9日
update docs #154911
已合并
共 18 个文件变更+441-357
Men/application-dev/reference/apis-basic-services-kit/capi-oh-commonevent-commonevent-publishinfo.md+4-4
| @@ -12,10 +12,10 @@ typedef struct CommonEvent_PublishInfo CommonEvent_PublishInfo | |||
| 12 | 12 | ||
| 13 | ## Overview | 13 | ## Overview |
| 14 | 14 | ||
| 15 | -Defines the property object used for publishing a common event. | 15 | +Defines the property object used for publishing a common event. This object encapsulates the property configuration required for publishing a common event. It is applicable to scenarios where an app needs to publish a custom common event and specify the publishing parameters. |
| 16 | 16 | ||
| 17 | -**Since**: 18 | 17 | +**Since:** 18 |
| 18 | 18 | ||
| 19 | -**Related modules**: [OH_CommonEvent](capi-oh-commonevent.md) | 19 | +**Related modules:** [OH_CommonEvent](capi-oh-commonevent.md) |
| 20 | 20 | ||
| 21 | -**Header file**: [oh_commonevent.h](capi-oh-commonevent-h.md) | 21 | +**Header file:** [oh_commonevent.h](capi-oh-commonevent-h.md) |
Men/application-dev/reference/apis-basic-services-kit/capi-oh-commonevent-commonevent-rcvdata.md+4-4
| @@ -12,10 +12,10 @@ typedef struct CommonEvent_RcvData CommonEvent_RcvData | |||
| 12 | 12 | ||
| 13 | ## Overview | 13 | ## Overview |
| 14 | 14 | ||
| 15 | -Defines a struct for the common event data. | 15 | +Defines a struct for the common event data. When a common event triggers a callback, this struct is used to pass the received event data to the developer. |
| 16 | 16 | ||
| 17 | -**Since**: 12 | 17 | +**Since:** 12 |
| 18 | 18 | ||
| 19 | -**Related modules**: [OH_CommonEvent](capi-oh-commonevent.md) | 19 | +**Related modules:** [OH_CommonEvent](capi-oh-commonevent.md) |
| 20 | 20 | ||
| 21 | -**Header file**: [oh_commonevent.h](capi-oh-commonevent-h.md) | 21 | +**Header file:** [oh_commonevent.h](capi-oh-commonevent-h.md) |
| @@ -12,10 +12,10 @@ typedef struct CommonEvent_SubscribeInfo CommonEvent_SubscribeInfo | |||
| 12 | 12 | ||
| 13 | ## Overview | 13 | ## Overview |
| 14 | 14 | ||
| 15 | -Defines a struct for the subscriber information. | 15 | +Defines a struct for the subscriber information of a common event. This struct is used to describe the configuration information of a subscriber. It is passed as a parameter when the API for creating a subscriber is called. |
| 16 | 16 | ||
| 17 | -**Since**: 12 | 17 | +**Since:** 12 |
| 18 | 18 | ||
| 19 | -**Related modules**: [OH_CommonEvent](capi-oh-commonevent.md) | 19 | +**Related modules:** [OH_CommonEvent](capi-oh-commonevent.md) |
| 20 | 20 | ||
| 21 | -**Header file**: [oh_commonevent.h](capi-oh-commonevent-h.md) | 21 | +**Header file:** [oh_commonevent.h](capi-oh-commonevent-h.md) |
| @@ -8,7 +8,39 @@ | |||
| 8 | 8 | ||
| 9 | ## Overview | 9 | ## Overview |
| 10 | 10 | ||
| 11 | -Defines the APIs for subscribing to and unsubscribing from common events and enumerates the error codes. | 11 | +Defines key operation functions for publishing, subscribing to, and unsubscribing from common events, event callback data access, and ordered event control, enumerates error codes, and defines core data types. |
| 12 | + | ||
| 13 | +**APIs used in combination** | ||
| 14 | + | ||
| 15 | +This module provides APIs for three processes: subscription, publishing, and ordered event processing. | ||
| 16 | + | ||
| 17 | +**Combination 1: subscribing to and processing common events** | ||
| 18 | + | ||
| 19 | +1. Call **OH_CommonEvent_CreateSubscribeInfo** to create subscriber information, declare the name of the event to be subscribed to, and set the publisher permissions and package name as required to filter the event source. | ||
| 20 | +2. Call **OH_CommonEvent_CreateSubscriber** to create a subscriber and register the callback function for receiving events. Then, call **OH_CommonEvent_Subscribe** to subscribe to a common event. After the subscription takes effect, wait for event delivery in the callback. | ||
| 21 | +3. When the event is triggered, obtain the event name, code, data, and publisher's package name from the callback parameter **CommonEvent_RcvData**, and then process the service logic. | ||
| 22 | +4. When the subscription is no longer needed, call **OH_CommonEvent_UnSubscribe** to unsubscribe from the event and release related resources. | ||
| 23 | + | ||
| 24 | +**Combination 2: publishing a common event that carries additional information** | ||
| 25 | + | ||
| 26 | +1. Call **OH_CommonEvent_CreatePublishInfo** to create a common event property object, and set the code, data, subscriber package name, subscriber permission, and additional information as required. | ||
| 27 | +2. Call **OH_CommonEvent_PublishWithInfo** to publish an event that carries the property. | ||
| 28 | + | ||
| 29 | +> If no additional property is required, you can call **OH_CommonEvent_Publish(event)** to publish the event. | ||
| 30 | + | ||
| 31 | +**Combination 3: processing ordered common events** | ||
| 32 | + | ||
| 33 | +Ordered common events are controlled by the subscriber handle in the subscription callback. The subscriber handle must be saved when the subscriber is created so that it can be used in the callback. | ||
| 34 | + | ||
| 35 | +1. When publishing common events, use **OH_CommonEvent_CreatePublishInfo(true)** to create the ordered event property. The events will be delivered to subscribers in sequence based on their priorities. | ||
| 36 | +2. The subscriber can use **OH_CommonEvent_SetCodeToSubscriber** and **OH_CommonEvent_SetDataToSubscriber** in the callback to set the code and data to be passed to subsequent subscribers. The subscriber can use **OH_CommonEvent_AbortCommonEvent** to mark the event as aborted and stop delivering the event to subsequent subscribers. | ||
| 37 | +3. After the callback processing is complete, you must call **OH_CommonEvent_FinishCommonEvent** to end the processing. Otherwise, the event cannot be delivered to subsequent subscribers. | ||
| 38 | + | ||
| 39 | +Note that this module follows the typical lifecycle of creation, use, and release. | ||
| 40 | + | ||
| 41 | +- **Subscriber object**: **CommonEvent_SubscribeInfo** and **CommonEvent_Subscriber**. The subscription takes effect after being created. After the subscription is canceled, the subscriber and subscription information must be destroyed in sequence to prevent memory leak. | ||
| 42 | +- **Publisher object**: **CommonEvent_PublishInfo** and **CommonEvent_Parameters**. After the publishing is complete, destroy the publishing information and additional information separately. They are independent of each other. | ||
| 43 | + | ||
| 12 | 44 | ||
| 13 | **Library**: libohcommonevent.so | 45 | **Library**: libohcommonevent.so |
| 14 | 46 | ||
| @@ -35,7 +67,7 @@ Defines the APIs for subscribing to and unsubscribing from common events and enu | |||
| 35 | | Name| typedef Keyword| Description| | 67 | | Name| typedef Keyword| Description| |
| 36 | |----|------------|----| | 68 | |----|------------|----| |
| 37 | | void | CommonEvent_Subscriber | Information about **CommonEvent_Subscriber**. | | 69 | | void | CommonEvent_Subscriber | Information about **CommonEvent_Subscriber**. | |
| 38 | -| void | CommonEvent_Parameters | Additional information about **CommonEvent_Subscriber**. | | 70 | +| void | CommonEvent_Parameters | Additional information about **CommonEvent_Parameters**. | |
| 39 | 71 | ||
| 40 | ### Enums | 72 | ### Enums |
| 41 | 73 | ||
| @@ -57,7 +89,7 @@ Defines the APIs for subscribing to and unsubscribing from common events and enu | |||
| 57 | | [CommonEvent_ErrCode OH_CommonEvent_Subscribe(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_subscribe) | - | Subscribes to a common event.| | 89 | | [CommonEvent_ErrCode OH_CommonEvent_Subscribe(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_subscribe) | - | Subscribes to a common event.| |
| 58 | | [CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_unsubscribe) | - | Unsubscribes from a common event.| | 90 | | [CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_unsubscribe) | - | Unsubscribes from a common event.| |
| 59 | | [const char* OH_CommonEvent_GetEventFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_geteventfromrcvdata) | - | Obtains the name of a common event.| | 91 | | [const char* OH_CommonEvent_GetEventFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_geteventfromrcvdata) | - | Obtains the name of a common event.| |
| 60 | -| [int32_t OH_CommonEvent_GetCodeFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getcodefromrcvdata) | - | Obtains the result data (integer type) of a common event.| | 92 | +| [int32_t OH_CommonEvent_GetCodeFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getcodefromrcvdata) | - | Obtains the result code (integer type) of a common event.| |
| 61 | | [const char* OH_CommonEvent_GetDataStrFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getdatastrfromrcvdata) | - | Obtains the result data (string type) of a common event.| | 93 | | [const char* OH_CommonEvent_GetDataStrFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getdatastrfromrcvdata) | - | Obtains the result data (string type) of a common event.| |
| 62 | | [const char* OH_CommonEvent_GetBundleNameFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getbundlenamefromrcvdata) | - | Obtains the bundle name of a common event.| | 94 | | [const char* OH_CommonEvent_GetBundleNameFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getbundlenamefromrcvdata) | - | Obtains the bundle name of a common event.| |
| 63 | | [const CommonEvent_Parameters* OH_CommonEvent_GetParametersFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getparametersfromrcvdata) | - | Obtains the additional information of a common event.| | 95 | | [const CommonEvent_Parameters* OH_CommonEvent_GetParametersFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getparametersfromrcvdata) | - | Obtains the additional information of a common event.| |
| @@ -127,7 +159,7 @@ Enumerates the error codes. | |||
| 127 | | COMMONEVENT_ERR_SENDING_REQUEST_FAILED = 1500007 | Failed to send IPC requests.| | 159 | | COMMONEVENT_ERR_SENDING_REQUEST_FAILED = 1500007 | Failed to send IPC requests.| |
| 128 | | COMMONEVENT_ERR_INIT_UNDONE = 1500008 | Services not initialized.| | 160 | | COMMONEVENT_ERR_INIT_UNDONE = 1500008 | Services not initialized.| |
| 129 | | COMMONEVENT_ERR_OBTAIN_SYSTEM_PARAMS = 1500009 | System error.| | 161 | | COMMONEVENT_ERR_OBTAIN_SYSTEM_PARAMS = 1500009 | System error.| |
| 130 | -| COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED = 1500010 | The number of subscribers exceeds the upper limit.| | 162 | +| COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED = 1500010 | The number of subscribers in the process exceeds the system limit (200).| |
| 131 | | COMMONEVENT_ERR_ALLOC_MEMORY_FAILED = 1500011 | Failed to allocate memory.| | 163 | | COMMONEVENT_ERR_ALLOC_MEMORY_FAILED = 1500011 | Failed to allocate memory.| |
| 132 | 164 | ||
| 133 | 165 | ||
| @@ -170,7 +202,7 @@ Creates the subscriber information. | |||
| 170 | | Name| Description| | 202 | | Name| Description| |
| 171 | | -- | -- | | 203 | | -- | -- | |
| 172 | | const char* events[] | Pointer to the common events. The valid number of subscribed common events is the smaller value between **eventsNum** and **events[]**.| | 204 | | const char* events[] | Pointer to the common events. The valid number of subscribed common events is the smaller value between **eventsNum** and **events[]**.| |
| 173 | -| int32_t eventsNum | Number of common events to subscribe.| | 205 | +| int32_t eventsNum | Number of common events to subscribe. The value is the length of the **events** array.| |
| 174 | 206 | ||
| 175 | **Returns** | 207 | **Returns** |
| 176 | 208 | ||
| @@ -317,7 +349,7 @@ Subscribes to a common event. | |||
| 317 | 349 | ||
| 318 | | Type| Description| | 350 | | Type| Description| |
| 319 | | -- | -- | | 351 | | -- | -- | |
| 320 | -| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): Operation is successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): The parameter is invalid.<br> [COMMONEVENT_ERR_SENDING_REQUEST_FAILED](capi-oh-commonevent-h.md#commonevent_errcode): Failed to send IPC requests.<br> [COMMONEVENT_ERR_INIT_UNDONE](capi-oh-commonevent-h.md#commonevent_errcode): The common event service is not initialized.<br> [COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED](capi-oh-commonevent-h.md#commonevent_errcode): The number of subscribers exceeds 200.<br> [COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode): Failed to allocate memory.| | 352 | +| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): Operation is successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): The parameter is invalid.<br> [COMMONEVENT_ERR_SENDING_REQUEST_FAILED](capi-oh-commonevent-h.md#commonevent_errcode): Failed to send IPC requests.<br> [COMMONEVENT_ERR_INIT_UNDONE](capi-oh-commonevent-h.md#commonevent_errcode): The common event service is not initialized.<br> [COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED](capi-oh-commonevent-h.md#commonevent_errcode): The number of subscribers in the process exceeds the system limit (200).<br> [COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode): Failed to allocate memory.| |
| 321 | 353 | ||
| 322 | ### OH_CommonEvent_UnSubscribe() | 354 | ### OH_CommonEvent_UnSubscribe() |
| 323 | 355 | ||
| @@ -367,7 +399,7 @@ Obtains the name of a common event. | |||
| 367 | 399 | ||
| 368 | | Type| Description| | 400 | | Type| Description| |
| 369 | | -- | -- | | 401 | | -- | -- | |
| 370 | -| const char* | Event name obtained.| | 402 | +| const char* | Name of a common event.| |
| 371 | 403 | ||
| 372 | ### OH_CommonEvent_GetCodeFromRcvData() | 404 | ### OH_CommonEvent_GetCodeFromRcvData() |
| 373 | 405 | ||
| @@ -392,7 +424,7 @@ Obtains the result code (integer type) of a common event. | |||
| 392 | 424 | ||
| 393 | | Type| Description| | 425 | | Type| Description| |
| 394 | | -- | -- | | 426 | | -- | -- | |
| 395 | -| int32_t | Result code obtained.| | 427 | +| int32_t | Result code (integer type) of a common event.| |
| 396 | 428 | ||
| 397 | ### OH_CommonEvent_GetDataStrFromRcvData() | 429 | ### OH_CommonEvent_GetDataStrFromRcvData() |
| 398 | 430 | ||
| @@ -417,7 +449,7 @@ Obtains the result data (string type) of a common event. | |||
| 417 | 449 | ||
| 418 | | Type| Description| | 450 | | Type| Description| |
| 419 | | -- | -- | | 451 | | -- | -- | |
| 420 | -| const char* | Result data obtained.| | 452 | +| const char* | Result data (string type) of a common event.| |
| 421 | 453 | ||
| 422 | ### OH_CommonEvent_GetBundleNameFromRcvData() | 454 | ### OH_CommonEvent_GetBundleNameFromRcvData() |
| 423 | 455 | ||
| @@ -492,7 +524,7 @@ Creates a property object of a common event. | |||
| 492 | 524 | ||
| 493 | | Type | Description| | 525 | | Type | Description| |
| 494 | |------------------------------| -- | | 526 | |------------------------------| -- | |
| 495 | -| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* | Returns the property object if the operation is successful; returns **null** otherwise.| | 527 | +| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* | Returns the property object if the operation is successful; returns **NULL** otherwise.| |
| 496 | 528 | ||
| 497 | ### OH_CommonEvent_DestroyPublishInfo() | 529 | ### OH_CommonEvent_DestroyPublishInfo() |
| 498 | 530 | ||
| @@ -558,7 +590,7 @@ Sets permissions for a common event. | |||
| 558 | | -- | -- | | 590 | | -- | -- | |
| 559 | | [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | Pointer to the property object of a common event.| | 591 | | [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | Pointer to the property object of a common event.| |
| 560 | | const char* permissions[] | Pointer to the array of permission names. The valid number of permissions is the smaller value between **num** and **permissions[]**.| | 592 | | const char* permissions[] | Pointer to the array of permission names. The valid number of permissions is the smaller value between **num** and **permissions[]**.| |
| 561 | -| int32_t num | Number of permissions.| | 593 | +| int32_t num | Number of permission names. The value is the length of the **permissions** array.| |
| 562 | 594 | ||
| 563 | **Returns** | 595 | **Returns** |
| 564 | 596 | ||
| @@ -595,7 +627,7 @@ Sets the result code (integer type) of a common event. | |||
| 595 | ### OH_CommonEvent_SetPublishInfoData() | 627 | ### OH_CommonEvent_SetPublishInfoData() |
| 596 | 628 | ||
| 597 | ```c | 629 | ```c |
| 598 | -CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoData(CommonEvent_PublishInfo* info,const char* data, size_t length) | 630 | +CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoData(CommonEvent_PublishInfo* info, const char* data, size_t length) |
| 599 | ``` | 631 | ``` |
| 600 | 632 | ||
| 601 | **Description** | 633 | **Description** |
| @@ -610,8 +642,8 @@ Sets the result data (string type) of a common event. | |||
| 610 | | Name| Description| | 642 | | Name| Description| |
| 611 | | -- | -- | | 643 | | -- | -- | |
| 612 | | [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | Pointer to the property object of a common event.| | 644 | | [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | Pointer to the property object of a common event.| |
| 613 | -| const char* data | Pointer to the result data to set. The valid data length is the smaller value between **length** and **data**.| | 645 | +| const char* data | Pointer to the result data to set. The value is a string. The valid data length is the smaller value between **length** and **data**.| |
| 614 | -| size_t length | Length of the result data.| | 646 | +| size_t length | Length of the result data. The value is the length of the **data** string.| |
| 615 | 647 | ||
| 616 | **Returns** | 648 | **Returns** |
| 617 | 649 | ||
| @@ -637,7 +669,7 @@ Sets the additional information of a common event. | |||
| 637 | | Name| Description| | 669 | | Name| Description| |
| 638 | | -- | -- | | 670 | | -- | -- | |
| 639 | | [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | Pointer to the property object of a common event.| | 671 | | [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | Pointer to the property object of a common event.| |
| 640 | -| CommonEvent_Parameters* param | Pointer to the additional information to set.| | 672 | +| [CommonEvent_Parameters](#variables)* param | Pointer to the additional information to set.| |
| 641 | 673 | ||
| 642 | **Returns** | 674 | **Returns** |
| 643 | 675 | ||
| @@ -661,7 +693,7 @@ Creates an additional information object of a common event. | |||
| 661 | 693 | ||
| 662 | | Type| Description| | 694 | | Type| Description| |
| 663 | | -- | -- | | 695 | | -- | -- | |
| 664 | -| [CommonEvent_Parameters](#variables)*| Returns additional information of the common event if operation is successful; returns **null** otherwise.| | 696 | +| [CommonEvent_Parameters](#variables)*| Returns additional information of the common event if operation is successful; returns **NULL** otherwise.| |
| 665 | 697 | ||
| 666 | ### OH_CommonEvent_DestroyParameters() | 698 | ### OH_CommonEvent_DestroyParameters() |
| 667 | 699 | ||
| @@ -727,7 +759,7 @@ Obtains the int data with a specific key from the additional information of a co | |||
| 727 | | -- | -- | | 759 | | -- | -- | |
| 728 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| | 760 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| |
| 729 | | const char* key | Pointer to the key.| | 761 | | const char* key | Pointer to the key.| |
| 730 | -| const int defaultValue | Default value.| | 762 | +| const int defaultValue | Default value, which is returned when the specified key does not exist.| |
| 731 | 763 | ||
| 732 | **Returns** | 764 | **Returns** |
| 733 | 765 | ||
| @@ -781,7 +813,7 @@ Obtains the int array with a specific key from the additional information of a c | |||
| 781 | | -- | -- | | 813 | | -- | -- | |
| 782 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| | 814 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| |
| 783 | | const char* key | Pointer to the key.| | 815 | | const char* key | Pointer to the key.| |
| 784 | -| int** array | Double pointer to the int array to obtain.| | 816 | +| int** array | Output parameter, which is used to receive the int array. The array memory is allocated internally by the function, and the caller does not need to allocate it in advance.| |
| 785 | 817 | ||
| 786 | **Returns** | 818 | **Returns** |
| 787 | 819 | ||
| @@ -836,7 +868,7 @@ Obtains the long data with a specific key from the additional information of a c | |||
| 836 | | -- | -- | | 868 | | -- | -- | |
| 837 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| | 869 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| |
| 838 | | const char* key | Pointer to the key.| | 870 | | const char* key | Pointer to the key.| |
| 839 | -| const long defaultValue | Default value.| | 871 | +| const long defaultValue | Default value, which is returned when the specified key does not exist.| |
| 840 | 872 | ||
| 841 | **Returns** | 873 | **Returns** |
| 842 | 874 | ||
| @@ -890,7 +922,7 @@ Obtains the long array with a specific key from the additional information of a | |||
| 890 | | -- | -- | | 922 | | -- | -- | |
| 891 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| | 923 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| |
| 892 | | const char* key | Pointer to the key.| | 924 | | const char* key | Pointer to the key.| |
| 893 | -| long** array | Double pointer to the long array to obtain.| | 925 | +| long** array | Output parameter, which is used to receive the long array. The array memory is allocated internally by the function, and the caller does not need to allocate it in advance.| |
| 894 | 926 | ||
| 895 | **Returns** | 927 | **Returns** |
| 896 | 928 | ||
| @@ -945,7 +977,7 @@ Obtains the Boolean data with a specific key from the additional information of | |||
| 945 | | -- | -- | | 977 | | -- | -- | |
| 946 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| | 978 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| |
| 947 | | const char* key | Pointer to the key.| | 979 | | const char* key | Pointer to the key.| |
| 948 | -| const bool defaultValue | Default value.| | 980 | +| const bool defaultValue | Default value, which is returned when the specified key does not exist.| |
| 949 | 981 | ||
| 950 | **Returns** | 982 | **Returns** |
| 951 | 983 | ||
| @@ -999,7 +1031,7 @@ Obtains the Boolean array with a specific key from the additional information of | |||
| 999 | | -- | -- | | 1031 | | -- | -- | |
| 1000 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| | 1032 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| |
| 1001 | | const char* key | Pointer to the key.| | 1033 | | const char* key | Pointer to the key.| |
| 1002 | -| bool** array | Double pointer to the Boolean array to obtain.| | 1034 | +| bool** array | Output parameter, which is used to receive the bool array. The array memory is allocated internally by the function, and the caller does not need to allocate it in advance.| |
| 1003 | 1035 | ||
| 1004 | **Returns** | 1036 | **Returns** |
| 1005 | 1037 | ||
| @@ -1054,7 +1086,7 @@ Obtains the character data with a specific key from the additional information o | |||
| 1054 | | -- | -- | | 1086 | | -- | -- | |
| 1055 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| | 1087 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| |
| 1056 | | const char* key | Pointer to the key.| | 1088 | | const char* key | Pointer to the key.| |
| 1057 | -| const char defaultValue | Default value.| | 1089 | +| const char defaultValue | Default value, which is returned when the specified key does not exist.| |
| 1058 | 1090 | ||
| 1059 | **Returns** | 1091 | **Returns** |
| 1060 | 1092 | ||
| @@ -1108,7 +1140,7 @@ Obtains the character array with a specific key from the additional information | |||
| 1108 | | -- | -- | | 1140 | | -- | -- | |
| 1109 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| | 1141 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| |
| 1110 | | const char* key | Pointer to the key.| | 1142 | | const char* key | Pointer to the key.| |
| 1111 | -| char** array | Double pointer to the character array to obtain.| | 1143 | +| char** array | Output parameter, which is used to receive the character array. The array memory is allocated internally by the function, and the caller does not need to allocate it in advance.| |
| 1112 | 1144 | ||
| 1113 | **Returns** | 1145 | **Returns** |
| 1114 | 1146 | ||
| @@ -1147,7 +1179,7 @@ Sets the character array with a specific key for the additional information of a | |||
| 1147 | ### OH_CommonEvent_GetDoubleFromParameters() | 1179 | ### OH_CommonEvent_GetDoubleFromParameters() |
| 1148 | 1180 | ||
| 1149 | ```c | 1181 | ```c |
| 1150 | -double OH_CommonEvent_GetDoubleFromParameters(const CommonEvent_Parameters* para, const char* key,const double defaultValue) | 1182 | +double OH_CommonEvent_GetDoubleFromParameters(const CommonEvent_Parameters* para, const char* key, const double defaultValue) |
| 1151 | ``` | 1183 | ``` |
| 1152 | 1184 | ||
| 1153 | **Description** | 1185 | **Description** |
| @@ -1163,7 +1195,7 @@ Obtains the double data with a specific key from the additional information of a | |||
| 1163 | | -- | -- | | 1195 | | -- | -- | |
| 1164 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| | 1196 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| |
| 1165 | | const char* key | Pointer to the key.| | 1197 | | const char* key | Pointer to the key.| |
| 1166 | -| const double defaultValue | Default value.| | 1198 | +| const double defaultValue | Default value, which is returned when the specified key does not exist.| |
| 1167 | 1199 | ||
| 1168 | **Returns** | 1200 | **Returns** |
| 1169 | 1201 | ||
| @@ -1217,7 +1249,7 @@ Obtains the double array with a specific key from the additional information of | |||
| 1217 | | -- | -- | | 1249 | | -- | -- | |
| 1218 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| | 1250 | | const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| |
| 1219 | | const char* key | Pointer to the key.| | 1251 | | const char* key | Pointer to the key.| |
| 1220 | -| double** array | Double pointer to the double array to obtain.| | 1252 | +| double** array | Output parameter, which is used to receive the double array. The array memory is allocated internally by the function, and the caller does not need to allocate it in advance.| |
| 1221 | 1253 | ||
| 1222 | **Returns** | 1254 | **Returns** |
| 1223 | 1255 | ||
| @@ -1503,7 +1535,7 @@ Obtains the result data (string type) of an ordered common event. | |||
| 1503 | 1535 | ||
| 1504 | | Type| Description| | 1536 | | Type| Description| |
| 1505 | | -- | -- | | 1537 | | -- | -- | |
| 1506 | -| const char* | Returns the result data obtained if the operation is successful; returns **null** otherwise.| | 1538 | +| const char* | Returns the result data obtained if the operation is successful; returns **NULL** otherwise.| |
| 1507 | 1539 | ||
| 1508 | ### OH_CommonEvent_SetDataToSubscriber() | 1540 | ### OH_CommonEvent_SetDataToSubscriber() |
| 1509 | 1541 | ||
| @@ -1524,7 +1556,7 @@ Sets the result data (string type) of an ordered common event. | |||
| 1524 | | -- | -- | | 1556 | | -- | -- | |
| 1525 | | [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| | 1557 | | [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| |
| 1526 | | const char* data | Pointer to the result data to set. The valid data length is the smaller value between **length** and **data**.| | 1558 | | const char* data | Pointer to the result data to set. The valid data length is the smaller value between **length** and **data**.| |
| 1527 | -| size_t length | Data length.| | 1559 | +| size_t length | Length of the data to be transferred, in bytes. The value is the length of the **data** string.| |
| 1528 | 1560 | ||
| 1529 | **Returns** | 1561 | **Returns** |
| 1530 | 1562 | ||
| @@ -8,15 +8,26 @@ | |||
| 8 | 8 | ||
| 9 | ## Overview | 9 | ## Overview |
| 10 | 10 | ||
| 11 | -Provides the capability of subscribing to and unsubscribing from common events. | 11 | +This module provides APIs of the Common Event Service, which are implemented in C. It provides cross-process event communication capabilities for apps based on the publication-subscription model. After a publisher publishes a common event, the system delivers the event to all subscribers who have subscribed to the event based on the event name. In this way, decoupled communication between apps and between apps and the system is implemented. |
| 12 | 12 | ||
| 13 | -**System capability**: SystemCapability.Notification.CommonEvent | 13 | +This module provides the following capabilities: |
| 14 | 14 | ||
| 15 | -**Since**: 12 | 15 | +- **Event subscription and unsubscription**: creates subscription information, creates subscribers, subscribes to or unsubscribes from specified common events, and uses a callback to receive event data when the event is triggered. |
| 16 | +- **Event publishing**: publishes common events. You can set the publishing attributes, such as ordered/disordered events, the permission, app package name, code, data, and additional information. | ||
| 17 | +- **Event data access**: obtains the event name, result code, result data, publisher app package name, and additional information (parameters and key-value (KV) pairs, supporting reading and writing of data of the int/long/bool/char/double types and their array types) from the callback data. | ||
| 18 | +- **Control of ordered common events**: terminates an ordered common event, clears the termination status, obtains/sets the result code and result data, and completes the event. | ||
| 19 | +- **System common event constants**: provide system-defined common event name constants (such as battery level change, screen on/off, Wi-Fi status, and USB status) to facilitate subscription to system status changes. | ||
| 20 | +- **Error codes**: enumerates the error codes that may be returned during operations. | ||
| 21 | + | ||
| 22 | +**Use scenarios:** When an app needs to detect system status changes (such as the battery level, screen status, network connection, Wi-Fi status, USB status, and package installation) or broadcast service messages between multiple apps, APIs provided by this module can be used to subscribe to or publish common events. | ||
| 23 | + | ||
| 24 | +**System capability:** SystemCapability.Notification.CommonEvent | ||
| 25 | + | ||
| 26 | +**Since:** 12 | ||
| 16 | 27 | ||
| 17 | ## Files | 28 | ## Files |
| 18 | 29 | ||
| 19 | | Name| Description| | 30 | | Name| Description| |
| 20 | | -- | -- | | 31 | | -- | -- | |
| 21 | -| [oh_commonevent.h](capi-oh-commonevent-h.md) | Defines the APIs for subscribing to and unsubscribing from common events and enumerates the error codes.| | 32 | +| [oh_commonevent.h](capi-oh-commonevent-h.md) | Provides operation functions for subscription, unsubscription, publishing, event data access, additional information read/write, and ordered event control, enumerates the error codes, and defines the core data types.| |
| 22 | -| [oh_commonevent_support.h](capi-oh-commonevent-support-h.md) | Provides common event constants defined by the system.| | 33 | +| [oh_commonevent_support.h](capi-oh-commonevent-support-h.md) | Provides system-defined common event name constants (such as **COMMON_EVENT_BATTERY_CHANGED** and **COMMON_EVENT_SCREEN_ON**) for reference during subscription. This file does not provide functions.| |
Men/application-dev/reference/apis-basic-services-kit/common_event/commonEventManager-definitions.md+1-1
| @@ -572,7 +572,7 @@ Indicates the action of a common event that the user unlocks the device. | |||
| 572 | 572 | ||
| 573 | > **NOTE** | 573 | > **NOTE** |
| 574 | > | 574 | > |
| 575 | - > This API is deprecated since API Version 10 and replaced by [COMMON_EVENT_SCREEN_UNLOCKED](#common_event_screen_unlocked). | 575 | + > This type is supported since API version 9 and deprecated since API version 10. You are advised to use [COMMON_EVENT_SCREEN_UNLOCKED](#common_event_screen_unlocked) instead. |
| 576 | 576 | ||
| 577 | **System capability**: SystemCapability.Notification.CommonEvent | 577 | **System capability**: SystemCapability.Notification.CommonEvent |
| 578 | 578 | ||
| @@ -18,17 +18,17 @@ The action field in the want parameter is null. | |||
| 18 | 18 | ||
| 19 | **Description** | 19 | **Description** |
| 20 | 20 | ||
| 21 | -This error code is reported when the **Action** attribute in the **want** object is null for the event to send. | 21 | +This error code is reported when the **action** attribute in the **want** object is null for the event to send. |
| 22 | 22 | ||
| 23 | **Possible Causes** | 23 | **Possible Causes** |
| 24 | 24 | ||
| 25 | -The **Action** attribute in the **want** object is null for the event to send. | 25 | +The **action** attribute in the **want** object is null for the common event to send. |
| 26 | 26 | ||
| 27 | **Solution** | 27 | **Solution** |
| 28 | 28 | ||
| 29 | -Make sure the **Action** attribute in the **want** object is not null. | 29 | +Make sure the **action** attribute in the **want** object is not null. |
| 30 | 30 | ||
| 31 | -## 1500002 Failed to Send Common Events from a Sandbox Application | 31 | +## 1500002 Failed to Send Common Events from a Sandbox Application |
| 32 | 32 | ||
| 33 | **Error Message** | 33 | **Error Message** |
| 34 | 34 | ||
| @@ -36,7 +36,7 @@ A sandbox application cannot send common events. | |||
| 36 | 36 | ||
| 37 | **Description** | 37 | **Description** |
| 38 | 38 | ||
| 39 | -This error code is reported when an attempt is made to send a common event from a sandbox application. | 39 | +This error code is reported when a sandbox application fails to send a common event. |
| 40 | 40 | ||
| 41 | **Possible Causes** | 41 | **Possible Causes** |
| 42 | 42 | ||
| @@ -44,9 +44,9 @@ Common events from a sandbox application are blocked. | |||
| 44 | 44 | ||
| 45 | **Solution** | 45 | **Solution** |
| 46 | 46 | ||
| 47 | -Check whether the application used to send a common event is a sandbox application. If so, switch to another application. | 47 | +Check whether the application that sends the common event is a sandbox application. |
| 48 | 48 | ||
| 49 | -## 1500003 Event Sending Frequency Is Too High | 49 | +## 1500003 Common Event Sending Frequency Is Too High |
| 50 | 50 | ||
| 51 | **Error Message** | 51 | **Error Message** |
| 52 | 52 | ||
| @@ -54,17 +54,17 @@ The common event sending frequency too high. | |||
| 54 | 54 | ||
| 55 | **Description** | 55 | **Description** |
| 56 | 56 | ||
| 57 | -This error code is reported when the application sends common events too frequently. | 57 | +The frequency at which the application sends common events exceeds the system limit. |
| 58 | 58 | ||
| 59 | **Possible Causes** | 59 | **Possible Causes** |
| 60 | 60 | ||
| 61 | -The number of common events sent by the application in a given time frame has reached the maximum. | 61 | +The number of events sent by the application within a short period of time exceeds the system limit, triggering frequency control. |
| 62 | 62 | ||
| 63 | **Solution** | 63 | **Solution** |
| 64 | 64 | ||
| 65 | -Do not send common events too frequently. | 65 | +Check whether the application sends common events too frequently. If so, reduce the event sending frequency or increase the sending interval and try again. |
| 66 | 66 | ||
| 67 | -## 1500004 Failed to Send System Common Events | 67 | +## 1500004 Failed to Send System Common Events |
| 68 | 68 | ||
| 69 | **Error Message** | 69 | **Error Message** |
| 70 | 70 | ||
| @@ -72,7 +72,7 @@ A third-party application cannot send system common events. | |||
| 72 | 72 | ||
| 73 | **Description** | 73 | **Description** |
| 74 | 74 | ||
| 75 | -This error code is reported when the application cannot send system common events. | 75 | +The third-party application fails to send system common events. |
| 76 | 76 | ||
| 77 | **Possible Causes** | 77 | **Possible Causes** |
| 78 | 78 | ||
| @@ -82,7 +82,7 @@ The application is not a system application or system service. | |||
| 82 | 82 | ||
| 83 | Make sure the application to send system common events is a system application or system service. | 83 | Make sure the application to send system common events is a system application or system service. |
| 84 | 84 | ||
| 85 | -## 1500005 Subscriber Not Found | 85 | +## 1500005 Subscriber Not Found |
| 86 | 86 | ||
| 87 | **Error Message** | 87 | **Error Message** |
| 88 | 88 | ||
| @@ -94,13 +94,13 @@ This error code is reported when the subscriber cannot be found. | |||
| 94 | 94 | ||
| 95 | **Possible Causes** | 95 | **Possible Causes** |
| 96 | 96 | ||
| 97 | -The subscriber is deleted. | 97 | +The subscriber has canceled the subscription and is deleted by the system. |
| 98 | 98 | ||
| 99 | **Solution** | 99 | **Solution** |
| 100 | 100 | ||
| 101 | Check whether the subscription has already been canceled. If the subscription has been canceled, the subscriber is deleted. | 101 | Check whether the subscription has already been canceled. If the subscription has been canceled, the subscriber is deleted. |
| 102 | 102 | ||
| 103 | -## 1500006 Invalid User ID | 103 | +## 1500006 Invalid User ID |
| 104 | 104 | ||
| 105 | **Error Message** | 105 | **Error Message** |
| 106 | 106 | ||
| @@ -119,7 +119,7 @@ The user ID is different from the system user ID, or the application is not a sy | |||
| 119 | 1. Make sure the current user ID is the same as the system user ID. | 119 | 1. Make sure the current user ID is the same as the system user ID. |
| 120 | 2. Make sure the application is a system application or system service. | 120 | 2. Make sure the application is a system application or system service. |
| 121 | 121 | ||
| 122 | -## 1500007 Failed to Send a Request Through IPC | 122 | +## 1500007 Failed to Send a Request Through IPC |
| 123 | 123 | ||
| 124 | **Error Message** | 124 | **Error Message** |
| 125 | 125 | ||
| @@ -131,13 +131,13 @@ This error code is reported when the attempt to send a request through IPC fails | |||
| 131 | 131 | ||
| 132 | **Possible Causes** | 132 | **Possible Causes** |
| 133 | 133 | ||
| 134 | -The connection object fails to be created. | 134 | +IPC connections are frequently established within a short period of time, causing system resources to be insufficient. As a result, the connection object fails to be created. |
| 135 | 135 | ||
| 136 | **Solution** | 136 | **Solution** |
| 137 | 137 | ||
| 138 | Do not set up connections frequently. Try again later. | 138 | Do not set up connections frequently. Try again later. |
| 139 | 139 | ||
| 140 | -## 1500008 Failed to Initialize the Common Event Service | 140 | +## 1500008 Failed to Initialize the Common Event Service |
| 141 | 141 | ||
| 142 | **Error Message** | 142 | **Error Message** |
| 143 | 143 | ||
| @@ -145,17 +145,17 @@ Failed to initialize the common event service. | |||
| 145 | 145 | ||
| 146 | **Description** | 146 | **Description** |
| 147 | 147 | ||
| 148 | -This error code is reported when an error occurs on the server. | 148 | +An error occurs in the initialization process of the common event server. |
| 149 | 149 | ||
| 150 | **Possible Causes** | 150 | **Possible Causes** |
| 151 | 151 | ||
| 152 | -A service exception occurs when the server processes data. | 152 | +A service exception occurs when the server initializes data processing. |
| 153 | 153 | ||
| 154 | **Solution** | 154 | **Solution** |
| 155 | 155 | ||
| 156 | Try again later. | 156 | Try again later. |
| 157 | 157 | ||
| 158 | -## 1500009 Failed to Obtain System Parameters | 158 | +## 1500009 Failed to Obtain System Parameters |
| 159 | 159 | ||
| 160 | **Error Message** | 160 | **Error Message** |
| 161 | 161 | ||
| @@ -173,7 +173,7 @@ A system fault occurs. | |||
| 173 | 173 | ||
| 174 | Try again later. | 174 | Try again later. |
| 175 | 175 | ||
| 176 | -## 1500010 The Number of Subscribers Exceeds the Upper Limit | 176 | +## 1500010 The Number of Subscribers Exceeds the Upper Limit |
| 177 | 177 | ||
| 178 | **Error Message** | 178 | **Error Message** |
| 179 | 179 | ||
| @@ -185,7 +185,7 @@ This error code is reported when the number of subscribers exceeds the upper lim | |||
| 185 | 185 | ||
| 186 | **Possible Causes** | 186 | **Possible Causes** |
| 187 | 187 | ||
| 188 | -The subscriber is not unregistered in a timely manner when it is no longer used. A maximum of 200 subscribers can be subscribed to in each process of the common event. All services in a process share the number of subscribers. | 188 | +The subscriber is not unregistered when it is no longer used. A maximum of 200 subscribers can be subscribed to in each process of the common event. All services in a process share the number of subscribers. |
| 189 | 189 | ||
| 190 | **Solution** | 190 | **Solution** |
| 191 | 191 | ||
| @@ -6,9 +6,9 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -The **StaticSubscriberExtensionContext** module, inherited from **StaticSubscriberExtensionAbility**, provides context for StaticSubscriberExtensionAbilities. | 9 | +The **StaticSubscriberExtensionContext** module, inherited from **ExtensionContext**, provides context for **StaticSubscriberExtensionAbility**. |
| 10 | 10 | ||
| 11 | -You can use the APIs of this module to start StaticSubscriberExtensionAbilities. | 11 | +You can use the APIs of this module to start **StaticSubscriberExtensionAbility**. |
| 12 | 12 | ||
| 13 | > **NOTE** | 13 | > **NOTE** |
| 14 | > | 14 | > |
| @@ -26,7 +26,7 @@ import { StaticSubscriberExtensionContext } from '@kit.BasicServicesKit'; | |||
| 26 | 26 | ||
| 27 | ## Usage | 27 | ## Usage |
| 28 | 28 | ||
| 29 | -Before using the **StaticSubscriberExtensionContext** module, you must first obtain a **StaticSubscriberExtensionAbility** instance. | 29 | +Before using the **StaticSubscriberExtensionContext** module, you must first use **StaticSubscriberExtensionAbility** to obtain the context. |
| 30 | 30 | ||
| 31 | ```ts | 31 | ```ts |
| 32 | import { StaticSubscriberExtensionAbility, StaticSubscriberExtensionContext } from '@kit.BasicServicesKit'; | 32 | import { StaticSubscriberExtensionAbility, StaticSubscriberExtensionContext } from '@kit.BasicServicesKit'; |
| @@ -36,11 +36,7 @@ import { StaticSubscriberExtensionAbility, StaticSubscriberExtensionContext } fr | |||
| 36 | 36 | ||
| 37 | startAbility(want: Want, callback: AsyncCallback<void>): void | 37 | startAbility(want: Want, callback: AsyncCallback<void>): void |
| 38 | 38 | ||
| 39 | -Starts an ability that belongs to the same application as this StaticSubscriberExtensionAbility. This API uses an asynchronous callback to return the result. | 39 | +Starts an ability that belongs to the same application as this **StaticSubscriberExtensionAbility**. This API uses an asynchronous callback to return the result. |
| 40 | - | ||
| 41 | -Observe the following when using this API: | ||
| 42 | - - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. | ||
| 43 | - - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. | ||
| 44 | 40 | ||
| 45 | **Required permissions**: ohos.permission.START_ABILITIES_FROM_BACKGROUND | 41 | **Required permissions**: ohos.permission.START_ABILITIES_FROM_BACKGROUND |
| 46 | 42 | ||
| @@ -52,8 +48,8 @@ Observe the following when using this API: | |||
| 52 | 48 | ||
| 53 | | Name | Type | Mandatory| Description | | 49 | | Name | Type | Mandatory| Description | |
| 54 | | -------- | ----------------------------------- | ---- | -------------------------- | | 50 | | -------- | ----------------------------------- | ---- | -------------------------- | |
| 55 | -| want | [Want](../apis-ability-kit/js-apis-wantAgent.md) | Yes | Want information about the target ability. | | 51 | +| want | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Want information about the target ability. | |
| 56 | -| callback | AsyncCallback<void> | Yes | Callback used to return the result.| | 52 | +| callback | AsyncCallback<void> | Yes | Callback used to receive the result of starting the ability.| |
| 57 | 53 | ||
| 58 | **Error codes** | 54 | **Error codes** |
| 59 | 55 | ||
| @@ -85,8 +81,8 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 85 | import { Want } from '@kit.AbilityKit'; | 81 | import { Want } from '@kit.AbilityKit'; |
| 86 | 82 | ||
| 87 | let want: Want = { | 83 | let want: Want = { |
| 88 | - bundleName: "com.example.myapp", | 84 | + bundleName: 'com.example.myapp', |
| 89 | - abilityName: "MyAbility" | 85 | + abilityName: 'MyAbility' |
| 90 | }; | 86 | }; |
| 91 | 87 | ||
| 92 | class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility { | 88 | class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility { |
| @@ -97,7 +93,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 97 | this.context.startAbility(want, (error: BusinessError) => { | 93 | this.context.startAbility(want, (error: BusinessError) => { |
| 98 | if (error) { | 94 | if (error) { |
| 99 | // Process service logic errors. | 95 | // Process service logic errors. |
| 100 | - console.error(`startAbility failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}.`); | 96 | + console.error(`startAbility failed, error.code: ${error.code}, error.message: ${error.message}.`); |
| 101 | return; | 97 | return; |
| 102 | } | 98 | } |
| 103 | // Carry out normal service processing. | 99 | // Carry out normal service processing. |
| @@ -117,11 +113,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 117 | 113 | ||
| 118 | startAbility(want: Want): Promise<void> | 114 | startAbility(want: Want): Promise<void> |
| 119 | 115 | ||
| 120 | -Starts an ability that belongs to the same application as this StaticSubscriberExtensionAbility. This API uses a promise to return the result. | 116 | +Starts an ability that belongs to the same application as this **StaticSubscriberExtensionAbility**. This API uses a promise to return the result. |
| 121 | - | ||
| 122 | -Observe the following when using this API: | ||
| 123 | - - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. | ||
| 124 | - - If **visible** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. | ||
| 125 | 117 | ||
| 126 | **Required permissions**: ohos.permission.START_ABILITIES_FROM_BACKGROUND | 118 | **Required permissions**: ohos.permission.START_ABILITIES_FROM_BACKGROUND |
| 127 | 119 | ||
| @@ -133,7 +125,7 @@ Observe the following when using this API: | |||
| 133 | 125 | ||
| 134 | | Name| Type | Mandatory| Description | | 126 | | Name| Type | Mandatory| Description | |
| 135 | | ------ | ----------------------------------- | ---- | ----------------------- | | 127 | | ------ | ----------------------------------- | ---- | ----------------------- | |
| 136 | -| want | [Want](../apis-ability-kit/js-apis-wantAgent.md) | Yes | Want information about the target ability.| | 128 | +| want | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Want information about the target ability.| |
| 137 | 129 | ||
| 138 | **Return value** | 130 | **Return value** |
| 139 | 131 | ||
| @@ -171,8 +163,8 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 171 | import { Want } from '@kit.AbilityKit'; | 163 | import { Want } from '@kit.AbilityKit'; |
| 172 | 164 | ||
| 173 | let want: Want = { | 165 | let want: Want = { |
| 174 | - bundleName: "com.example.myapp", | 166 | + bundleName: 'com.example.myapp', |
| 175 | - abilityName: "MyAbility" | 167 | + abilityName: 'MyAbility' |
| 176 | }; | 168 | }; |
| 177 | 169 | ||
| 178 | class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility { | 170 | class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility { |
| @@ -186,7 +178,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 186 | }) | 178 | }) |
| 187 | .catch((error: BusinessError) => { | 179 | .catch((error: BusinessError) => { |
| 188 | // Process service logic errors. | 180 | // Process service logic errors. |
| 189 | - console.error(`startAbility failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}.`); | 181 | + console.error(`startAbility failed, error.code: ${error.code}, error.message: ${error.message}.`); |
| 190 | }); | 182 | }); |
| 191 | } catch (paramError) { | 183 | } catch (paramError) { |
| 192 | // Process input parameter errors. | 184 | // Process input parameter errors. |
| @@ -6,7 +6,13 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -The **StaticSubscriberExtensionAbility** module provides Extension abilities for static subscribers. | 9 | +This module provides extension abilities of Basic Services Kit for static subscribers, which can be used to subscribe to common events in static mode. Static subscription enables receiving common events without keeping the app running in the background. This ability is applicable to scenarios where system services or system apps need to perform background processing when specific common events occur. |
| 10 | + | ||
| 11 | +**StaticSubscriberExtensionAbility** provides the **onReceiveEvent** method and the **context** attribute. The **context** attribute is of the [StaticSubscriberExtensionContext](./js-apis-application-StaticSubscriberExtensionContext-sys.md) type, which is the running context of the extension ability. It is inherited from **ExtensionContext** and provides **startAbility** to start other abilities in the same app during event processing. | ||
| 12 | + | ||
| 13 | +**APIs used in combination** | ||
| 14 | + | ||
| 15 | +The typical process of this module is as follows: Inherit the base class, override **onReceiveEvent**, start a callback, read the event data, and start the target ability. Note that **context.startAbility** can start only the abilities that belong to the same app as the current **StaticSubscriberExtensionAbility**. | ||
| 10 | 16 | ||
| 11 | > **NOTE** | 17 | > **NOTE** |
| 12 | > | 18 | > |
| @@ -30,31 +36,33 @@ import { StaticSubscriberExtensionAbility } from '@kit.BasicServicesKit'; | |||
| 30 | 36 | ||
| 31 | | Name | Type | Read Only| Optional| Description | | 37 | | Name | Type | Read Only| Optional| Description | |
| 32 | | ------- | ------------------------------------------------------------ | ---- | ---- | -------- | | 38 | | ------- | ------------------------------------------------------------ | ---- | ---- | -------- | |
| 33 | -| context<sup>10+</sup> | [StaticSubscriberExtensionContext](js-apis-application-StaticSubscriberExtensionContext-sys.md) | No | No | Context of the ExtensionAbility.| | 39 | +| context<sup>10+</sup> | [StaticSubscriberExtensionContext](js-apis-application-StaticSubscriberExtensionContext-sys.md) | No | No | Context of the extension ability subscribed to in static mode.| |
| 34 | 40 | ||
| 35 | ## StaticSubscriberExtensionAbility.onReceiveEvent | 41 | ## StaticSubscriberExtensionAbility.onReceiveEvent |
| 36 | 42 | ||
| 37 | onReceiveEvent(event: CommonEventData): void | 43 | onReceiveEvent(event: CommonEventData): void |
| 38 | 44 | ||
| 39 | -Represents a callback of the common event of a static subscriber. | 45 | +Defines a callback to be invoked when a common event is triggered in static mode. |
| 40 | 46 | ||
| 41 | -**System capability**: SystemCapability.Ability.AbilityRuntime.Core | 47 | +**Model restriction:** This API can be used only in the stage model. |
| 42 | 48 | ||
| 43 | -**System API**: This is a system API. | 49 | +**System capability:** SystemCapability.Ability.AbilityRuntime.Core |
| 50 | + | ||
| 51 | +**System API:** This is a system API. | ||
| 44 | 52 | ||
| 45 | **Parameters** | 53 | **Parameters** |
| 46 | 54 | ||
| 47 | | Name| Type| Mandatory| Description| | 55 | | Name| Type| Mandatory| Description| |
| 48 | | -------- | -------- | -------- | -------- | | 56 | | -------- | -------- | -------- | -------- | |
| 49 | -| event | [CommonEventData](./js-apis-inner-commonEvent-commonEventData.md) | Yes| Common event of a static subscriber.| | 57 | +| event | [CommonEventData](./js-apis-inner-commonEvent-commonEventData.md) | Yes| Common event data received through static subscription.| |
| 50 | 58 | ||
| 51 | **Example** | 59 | **Example** |
| 52 | ```ts | 60 | ```ts |
| 53 | import { commonEventManager } from '@kit.BasicServicesKit'; | 61 | import { commonEventManager } from '@kit.BasicServicesKit'; |
| 54 | 62 | ||
| 55 | - class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility { | 63 | + class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility { |
| 56 | - onReceiveEvent(event: commonEventManager.CommonEventData) { | 64 | + onReceiveEvent(event: commonEventManager.CommonEventData) { |
| 57 | - console.info(`onReceiveEvent, event: ${JSON.stringify(event)}`); | 65 | + console.info(`onReceiveEvent, event: ${JSON.stringify(event)}`); |
| 58 | - } | ||
| 59 | } | 66 | } |
| 67 | + } | ||
| 60 | ``` | 68 | ``` |
| @@ -6,7 +6,7 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -The **CommonEvent** module provides capabilities to publish, subscribe to, and unsubscribe from common events, as well as obtain and modify the common event result code and result data. | 9 | +This module provides APIs to publish, subscribe to, and unsubscribe from common events, as well as obtain and modify the common event result code and result data. It is applicable to scenarios where system services or apps communicate with each other through common events. This module helps you publish and subscribe to events across apps, improving collaboration efficiency between apps. |
| 10 | 10 | ||
| 11 | > **NOTE** | 11 | > **NOTE** |
| 12 | > | 12 | > |
| @@ -22,7 +22,7 @@ import commonEvent from '@ohos.commonEvent'; | |||
| 22 | 22 | ||
| 23 | ## Support | 23 | ## Support |
| 24 | 24 | ||
| 25 | -A system common event is an event that is published by a system service or system application and requires specific permissions to subscribe to. To publish or subscribe to this type of event, you must follow the event-specific definitions. | 25 | +System common events refer to events released by system services or system apps. Subscribing to these events requires specific permissions. To publish or subscribe to this type of event, you must follow the event-specific definitions. |
| 26 | 26 | ||
| 27 | For details about the definitions of all system common events, see [System Common Events](./common_event/commonEvent-definitions.md). | 27 | For details about the definitions of all system common events, see [System Common Events](./common_event/commonEvent-definitions.md). |
| 28 | 28 | ||
| @@ -45,8 +45,8 @@ Publishes a common event to a specific user. This API uses an asynchronous callb | |||
| 45 | | Name | Type | Mandatory| Description | | 45 | | Name | Type | Mandatory| Description | |
| 46 | | -------- | -------------------- | ---- | ---------------------------------- | | 46 | | -------- | -------------------- | ---- | ---------------------------------- | |
| 47 | | event | string | Yes | Name of the common event to publish. | | 47 | | event | string | Yes | Name of the common event to publish. | |
| 48 | -| userId | number | Yes | User ID.| | 48 | +| userId | number | Yes | ID of the user to whom the common event is published.| |
| 49 | -| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | | 49 | +| callback | AsyncCallback\<void> | Yes | Callback used to return the common event publication result. | |
| 50 | 50 | ||
| 51 | **Example** | 51 | **Example** |
| 52 | 52 | ||
| @@ -54,19 +54,19 @@ Publishes a common event to a specific user. This API uses an asynchronous callb | |||
| 54 | import Base from '@ohos.base'; | 54 | import Base from '@ohos.base'; |
| 55 | 55 | ||
| 56 | // Callback for common event publication | 56 | // Callback for common event publication |
| 57 | -function publishCB(err:Base.BusinessError) { | 57 | +let publishCallBack = (err:Base.BusinessError) => { |
| 58 | if (err.code) { | 58 | if (err.code) { |
| 59 | - console.error(`publishAsUser failed, code is ${err.code}`); | 59 | + console.error(`Failed to publishAsUser. Code: ${err.code}, message: ${err.message}`); |
| 60 | } else { | 60 | } else { |
| 61 | - console.info("publishAsUser"); | 61 | + console.info('publishAsUser'); |
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | // Specify the user to whom the common event will be published. | 65 | // Specify the user to whom the common event will be published. |
| 66 | -let userId = 100; | 66 | +const userId = 100; |
| 67 | 67 | ||
| 68 | // Publish a common event. | 68 | // Publish a common event. |
| 69 | -commonEvent.publishAsUser("event", userId, publishCB); | 69 | +commonEvent.publishAsUser('event', userId, publishCallBack); |
| 70 | ``` | 70 | ``` |
| 71 | 71 | ||
| 72 | ## commonEvent.publishAsUser<sup>(deprecated)</sup> | 72 | ## commonEvent.publishAsUser<sup>(deprecated)</sup> |
| @@ -76,6 +76,7 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca | |||
| 76 | Publishes a common event with given properties to a specific user. This API uses an asynchronous callback to return the result. | 76 | Publishes a common event with given properties to a specific user. This API uses an asynchronous callback to return the result. |
| 77 | 77 | ||
| 78 | > **NOTE** | 78 | > **NOTE** |
| 79 | +> | ||
| 79 | > This API has been supported since API version 8 and deprecated since API version 9. You are advised to use [commonEventManager.publishAsUser](js-apis-commonEventManager-sys.md#commoneventmanagerpublishasuser-1) instead. | 80 | > This API has been supported since API version 8 and deprecated since API version 9. You are advised to use [commonEventManager.publishAsUser](js-apis-commonEventManager-sys.md#commoneventmanagerpublishasuser-1) instead. |
| 80 | 81 | ||
| 81 | **System capability**: SystemCapability.Notification.CommonEvent | 82 | **System capability**: SystemCapability.Notification.CommonEvent |
| @@ -87,9 +88,9 @@ Publishes a common event with given properties to a specific user. This API uses | |||
| 87 | | Name | Type | Mandatory| Description | | 88 | | Name | Type | Mandatory| Description | |
| 88 | | -------- | ---------------------- | ---- | ---------------------- | | 89 | | -------- | ---------------------- | ---- | ---------------------- | |
| 89 | | event | string | Yes | Name of the common event to publish. | | 90 | | event | string | Yes | Name of the common event to publish. | |
| 90 | -| userId | number | Yes| User ID.| | 91 | +| userId | number | Yes| ID of the user to whom the common event is published.| |
| 91 | | options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Properties of the common event to publish.| | 92 | | options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Properties of the common event to publish.| |
| 92 | -| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | | 93 | +| callback | AsyncCallback\<void> | Yes | Callback used to return the common event publication result. | |
| 93 | 94 | ||
| 94 | **Example** | 95 | **Example** |
| 95 | 96 | ||
| @@ -100,16 +101,16 @@ import CommonEventManager from '@ohos.commonEventManager'; | |||
| 100 | 101 | ||
| 101 | // Information of a common event. | 102 | // Information of a common event. |
| 102 | let options:CommonEventManager.CommonEventPublishData = { | 103 | let options:CommonEventManager.CommonEventPublishData = { |
| 103 | - code: 0, // Initial code of the common event. | 104 | + code: 0, // Initial code of the common event. |
| 104 | - data: "initial data",// Initial data of the common event. | 105 | + data: 'initial data', // Initial data of the common event. |
| 105 | -} | 106 | +}; |
| 106 | 107 | ||
| 107 | // Callback for common event publication | 108 | // Callback for common event publication |
| 108 | -function publishCB(err:Base.BusinessError) { | 109 | +let publishCallBack = (err:Base.BusinessError) => { |
| 109 | if (err.code) { | 110 | if (err.code) { |
| 110 | - console.error(`publishAsUser failed, code is ${err.code}`); | 111 | + console.error(`Failed to publishAsUser. Code: ${err.code}, message: ${err.message}`); |
| 111 | } else { | 112 | } else { |
| 112 | - console.info("publishAsUser"); | 113 | + console.info('publishAsUser'); |
| 113 | } | 114 | } |
| 114 | } | 115 | } |
| 115 | 116 | ||
| @@ -117,5 +118,5 @@ function publishCB(err:Base.BusinessError) { | |||
| 117 | let userId = 100; | 118 | let userId = 100; |
| 118 | 119 | ||
| 119 | // Publish a common event. | 120 | // Publish a common event. |
| 120 | -commonEvent.publishAsUser("event", userId, options, publishCB); | 121 | +commonEvent.publishAsUser('event', userId, options, publishCallBack); |
| 121 | ``` | 122 | ``` |
| @@ -28,7 +28,7 @@ For details about the definitions of all system common events, see [System Commo | |||
| 28 | 28 | ||
| 29 | publish(event: string, callback: AsyncCallback\<void>): void | 29 | publish(event: string, callback: AsyncCallback\<void>): void |
| 30 | 30 | ||
| 31 | -Publishes a common event. This API uses an asynchronous callback to return the result. | 31 | +Publishes a common event with given properties. This API uses an asynchronous callback to return the result. |
| 32 | 32 | ||
| 33 | > **NOTE** | 33 | > **NOTE** |
| 34 | > This API has been supported since API version 7 and deprecated since API version 9. You are advised to use [commonEventManager.publish](js-apis-commonEventManager.md#commoneventmanagerpublish) instead. | 34 | > This API has been supported since API version 7 and deprecated since API version 9. You are advised to use [commonEventManager.publish](js-apis-commonEventManager.md#commoneventmanagerpublish) instead. |
| @@ -40,7 +40,7 @@ Publishes a common event. This API uses an asynchronous callback to return the r | |||
| 40 | | Name | Type | Mandatory| Description | | 40 | | Name | Type | Mandatory| Description | |
| 41 | | -------- | -------------------- | ---- | ---------------------- | | 41 | | -------- | -------------------- | ---- | ---------------------- | |
| 42 | | event | string | Yes | Name of the common event to publish.| | 42 | | event | string | Yes | Name of the common event to publish.| |
| 43 | -| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| | 43 | +| callback | AsyncCallback\<void> | Yes | Callback used to return the result of publishing a common event.| |
| 44 | 44 | ||
| 45 | **Example** | 45 | **Example** |
| 46 | 46 | ||
| @@ -48,16 +48,16 @@ Publishes a common event. This API uses an asynchronous callback to return the r | |||
| 48 | import Base from '@ohos.base'; | 48 | import Base from '@ohos.base'; |
| 49 | 49 | ||
| 50 | // Callback for common event publication. | 50 | // Callback for common event publication. |
| 51 | -function publishCB(err:Base.BusinessError) { | 51 | +let publishCallBack = (err: Base.BusinessError) => { |
| 52 | if (err.code) { | 52 | if (err.code) { |
| 53 | - console.error(`publish failed, code is ${err.code}`); | 53 | + console.error(`publish failed, code is ${err.code}, message is ${err.message}`); |
| 54 | } else { | 54 | } else { |
| 55 | - console.info("publish"); | 55 | + console.info('publish'); |
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | // Publish a common event. | 59 | // Publish a common event. |
| 60 | -commonEvent.publish("event", publishCB); | 60 | +commonEvent.publish("event", publishCallBack); |
| 61 | ``` | 61 | ``` |
| 62 | 62 | ||
| 63 | ## commonEvent.publish<sup>(deprecated)</sup> | 63 | ## commonEvent.publish<sup>(deprecated)</sup> |
| @@ -77,7 +77,7 @@ Publishes a common event with given properties. This API uses an asynchronous ca | |||
| 77 | | -------- | ---------------------- | ---- | ---------------------- | | 77 | | -------- | ---------------------- | ---- | ---------------------- | |
| 78 | | event | string | Yes | Name of the common event to publish. | | 78 | | event | string | Yes | Name of the common event to publish. | |
| 79 | | options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Properties of the common event to publish.| | 79 | | options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Properties of the common event to publish.| |
| 80 | -| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | | 80 | +| callback | AsyncCallback\<void> | Yes | Callback used to return the result of publishing a common event. | |
| 81 | 81 | ||
| 82 | **Example** | 82 | **Example** |
| 83 | 83 | ||
| @@ -91,19 +91,19 @@ let options:CommonEventManager.CommonEventPublishData = { | |||
| 91 | code: 0, // Initial code of the common event. | 91 | code: 0, // Initial code of the common event. |
| 92 | data: "initial data", // Initial data of the common event. | 92 | data: "initial data", // Initial data of the common event. |
| 93 | isOrdered: true // The common event is an ordered one. | 93 | isOrdered: true // The common event is an ordered one. |
| 94 | -} | 94 | +}; |
| 95 | 95 | ||
| 96 | // Callback for common event publication. | 96 | // Callback for common event publication. |
| 97 | -function publishCB(err:Base.BusinessError) { | 97 | +let publishCallBack = (err: Base.BusinessError) => { |
| 98 | if (err.code) { | 98 | if (err.code) { |
| 99 | - console.error(`publish failed, code is ${err.code}`); | 99 | + console.error(`publish failed, code is ${err.code}, message is ${err.message}`); |
| 100 | } else { | 100 | } else { |
| 101 | console.info("publish"); | 101 | console.info("publish"); |
| 102 | } | 102 | } |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | // Publish a common event. | 105 | // Publish a common event. |
| 106 | -commonEvent.publish("event", options, publishCB); | 106 | +commonEvent.publish("event", options, publishCallBack); |
| 107 | ``` | 107 | ``` |
| 108 | 108 | ||
| 109 | ## commonEvent.createSubscriber<sup>(deprecated)</sup> | 109 | ## commonEvent.createSubscriber<sup>(deprecated)</sup> |
| @@ -139,9 +139,9 @@ let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { | |||
| 139 | }; | 139 | }; |
| 140 | 140 | ||
| 141 | // Callback for subscriber creation. | 141 | // Callback for subscriber creation. |
| 142 | -function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) { | 142 | +let createCallBack = (err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) => { |
| 143 | if (err.code) { | 143 | if (err.code) { |
| 144 | - console.error(`createSubscriber failed, code is ${err.code}`); | 144 | + console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); |
| 145 | } else { | 145 | } else { |
| 146 | console.info("createSubscriber"); | 146 | console.info("createSubscriber"); |
| 147 | subscriber = commonEventSubscriber; | 147 | subscriber = commonEventSubscriber; |
| @@ -149,7 +149,7 @@ function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManag | |||
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | // Create a subscriber. | 151 | // Create a subscriber. |
| 152 | -commonEvent.createSubscriber(subscribeInfo, createCB); | 152 | +commonEvent.createSubscriber(subscribeInfo, createCallBack); |
| 153 | ``` | 153 | ``` |
| 154 | 154 | ||
| 155 | ## commonEvent.createSubscriber<sup>(deprecated)</sup> | 155 | ## commonEvent.createSubscriber<sup>(deprecated)</sup> |
| @@ -192,7 +192,7 @@ commonEvent.createSubscriber(subscribeInfo).then((commonEventSubscriber:CommonEv | |||
| 192 | console.info("createSubscriber"); | 192 | console.info("createSubscriber"); |
| 193 | subscriber = commonEventSubscriber; | 193 | subscriber = commonEventSubscriber; |
| 194 | }).catch((err:Base.BusinessError) => { | 194 | }).catch((err:Base.BusinessError) => { |
| 195 | - console.error(`createSubscriber failed, code is ${err.code}`); | 195 | + console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); |
| 196 | }); | 196 | }); |
| 197 | ``` | 197 | ``` |
| 198 | 198 | ||
| @@ -212,7 +212,7 @@ Subscribes to common events. This API uses an asynchronous callback to return th | |||
| 212 | | Name | Type | Mandatory| Description | | 212 | | Name | Type | Mandatory| Description | |
| 213 | | ---------- | ---------------------------------------------------- | ---- | -------------------------------- | | 213 | | ---------- | ---------------------------------------------------- | ---- | -------------------------------- | |
| 214 | | subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md) | Yes | Subscriber object. | | 214 | | subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md) | Yes | Subscriber object. | |
| 215 | -| callback | AsyncCallback\<[CommonEventData](./js-apis-inner-commonEvent-commonEventData.md)> | Yes | Callback used to return the result.| | 215 | +| callback | AsyncCallback\<[CommonEventData](./js-apis-inner-commonEvent-commonEventData.md)> | Yes | Callback to be invoked when a common event is subscribed to.| |
| 216 | 216 | ||
| 217 | **Example** | 217 | **Example** |
| 218 | 218 | ||
| @@ -220,7 +220,7 @@ Subscribes to common events. This API uses an asynchronous callback to return th | |||
| 220 | import Base from '@ohos.base'; | 220 | import Base from '@ohos.base'; |
| 221 | import CommonEventManager from '@ohos.commonEventManager'; | 221 | import CommonEventManager from '@ohos.commonEventManager'; |
| 222 | 222 | ||
| 223 | -let subscriber:CommonEventManager.CommonEventSubscriber;// Used to save the created subscriber object for subsequent subscription and unsubscription. | 223 | +let subscriber:CommonEventManager.CommonEventSubscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. |
| 224 | 224 | ||
| 225 | // Subscriber information. | 225 | // Subscriber information. |
| 226 | let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { | 226 | let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { |
| @@ -228,28 +228,28 @@ let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { | |||
| 228 | }; | 228 | }; |
| 229 | 229 | ||
| 230 | // Callback for common event subscription. | 230 | // Callback for common event subscription. |
| 231 | -function subscribeCB(err:Base.BusinessError, data:CommonEventManager.CommonEventData) { | 231 | +let subscribeCallBack = (err:Base.BusinessError, data:CommonEventManager.CommonEventData) => { |
| 232 | if (err.code) { | 232 | if (err.code) { |
| 233 | - console.error(`subscribe failed, code is ${err.code}`); | 233 | + console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); |
| 234 | } else { | 234 | } else { |
| 235 | console.info("subscribe " + JSON.stringify(data)); | 235 | console.info("subscribe " + JSON.stringify(data)); |
| 236 | } | 236 | } |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | // Callback for subscriber creation. | 239 | // Callback for subscriber creation. |
| 240 | -function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) { | 240 | +let createCallBack = (err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) => { |
| 241 | if (err.code) { | 241 | if (err.code) { |
| 242 | - console.error(`createSubscriber failed, code is ${err.code}`); | 242 | + console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); |
| 243 | } else { | 243 | } else { |
| 244 | console.info("createSubscriber"); | 244 | console.info("createSubscriber"); |
| 245 | subscriber = commonEventSubscriber; | 245 | subscriber = commonEventSubscriber; |
| 246 | - // Subscribe to a common event. | 246 | + // Subscribe to a common event. |
| 247 | - commonEvent.subscribe(subscriber, subscribeCB); | 247 | + commonEvent.subscribe(subscriber, subscribeCallBack); |
| 248 | } | 248 | } |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | // Create a subscriber. | 251 | // Create a subscriber. |
| 252 | -commonEvent.createSubscriber(subscribeInfo, createCB); | 252 | +commonEvent.createSubscriber(subscribeInfo, createCallBack); |
| 253 | ``` | 253 | ``` |
| 254 | 254 | ||
| 255 | ## commonEvent.unsubscribe<sup>(deprecated)</sup> | 255 | ## commonEvent.unsubscribe<sup>(deprecated)</sup> |
| @@ -284,38 +284,39 @@ let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { | |||
| 284 | }; | 284 | }; |
| 285 | 285 | ||
| 286 | // Callback for common event subscription. | 286 | // Callback for common event subscription. |
| 287 | -function subscribeCB(err:Base.BusinessError, data:CommonEventManager.CommonEventData) { | 287 | +let subscribeCallBack = (err:Base.BusinessError, data:CommonEventManager.CommonEventData) => { |
| 288 | if (err.code) { | 288 | if (err.code) { |
| 289 | - console.error(`subscribe failed, code is ${err.code}`); | 289 | + console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); |
| 290 | } else { | 290 | } else { |
| 291 | console.info("subscribe " + JSON.stringify(data)); | 291 | console.info("subscribe " + JSON.stringify(data)); |
| 292 | } | 292 | } |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | // Callback for subscriber creation. | 295 | // Callback for subscriber creation. |
| 296 | -function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) { | 296 | +let createCallBack = (err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) => { |
| 297 | if (err.code) { | 297 | if (err.code) { |
| 298 | - console.error(`createSubscriber failed, code is ${err.code}`); | 298 | + console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); |
| 299 | } else { | 299 | } else { |
| 300 | console.info("createSubscriber"); | 300 | console.info("createSubscriber"); |
| 301 | subscriber = commonEventSubscriber; | 301 | subscriber = commonEventSubscriber; |
| 302 | - // Subscribe to a common event. | 302 | + // Subscribe to a common event. |
| 303 | - commonEvent.subscribe(subscriber, subscribeCB); | 303 | + commonEvent.subscribe(subscriber, subscribeCallBack); |
| 304 | } | 304 | } |
| 305 | } | 305 | } |
| 306 | 306 | ||
| 307 | // Callback for common event unsubscription. | 307 | // Callback for common event unsubscription. |
| 308 | -function unsubscribeCB(err:Base.BusinessError) { | 308 | +let unsubscribeCallback = (err: Base.BusinessError) => { |
| 309 | if (err.code) { | 309 | if (err.code) { |
| 310 | - console.error(`unsubscribe failed, code is ${err.code}`); | 310 | + console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`); |
| 311 | } else { | 311 | } else { |
| 312 | console.info("unsubscribe"); | 312 | console.info("unsubscribe"); |
| 313 | } | 313 | } |
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | // Create a subscriber. | 316 | // Create a subscriber. |
| 317 | -commonEvent.createSubscriber(subscribeInfo, createCB); | 317 | +commonEvent.createSubscriber(subscribeInfo, createCallBack); |
| 318 | 318 | ||
| 319 | // Unsubscribe from the common event. | 319 | // Unsubscribe from the common event. |
| 320 | -commonEvent.unsubscribe(subscriber, unsubscribeCB); | 320 | +// Note: This API must be called after the subscriber is successfully created (that is, after the createCallBack callback is executed). Only the API usage is displayed here. |
| 321 | +commonEvent.unsubscribe(subscriber, unsubscribeCallback); | ||
| 321 | ``` | 322 | ``` |
| @@ -6,7 +6,7 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -This module provides common event capabilities to publish, subscribe to, and unsubscribe from common events. | 9 | +This module provides system APIs to publish common events to specified users, remove sticky common events, enable or disable static subscription events. Sticky common events are retained by the system after being published, allowing new subscribers to receive them. Non-sticky events are delivered only to subscribers who were registered at the time of publication. |
| 10 | 10 | ||
| 11 | > **NOTE** | 11 | > **NOTE** |
| 12 | > | 12 | > |
| @@ -22,11 +22,11 @@ import { commonEventManager } from '@kit.BasicServicesKit'; | |||
| 22 | 22 | ||
| 23 | ## Support | 23 | ## Support |
| 24 | 24 | ||
| 25 | -A system common event is an event that is published by a system service or system application and requires specific permissions to subscribe to. To publish or subscribe to this type of event, you must follow the event-specific definitions. | 25 | +A system common event is an event that is published by a system service or system app and requires specific permissions to subscribe to. To publish or subscribe to this type of event, you must follow the event-specific definitions. |
| 26 | 26 | ||
| 27 | -For details about the enum definitions of all system common events, see [System Common Events](./common_event/commonEventManager-definitions.md). | 27 | +For details about the enums of all system common events, see [System Common Events (System API)](./common_event/commonEventManager-definitions-sys.md). |
| 28 | 28 | ||
| 29 | -## commonEventManager.publishAsUser<sup> | 29 | +## commonEventManager.publishAsUser |
| 30 | 30 | ||
| 31 | publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): void | 31 | publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): void |
| 32 | 32 | ||
| @@ -40,8 +40,8 @@ Publishes a common event to a specified user. This API uses an asynchronous call | |||
| 40 | 40 | ||
| 41 | | Name | Type | Mandatory| Description | | 41 | | Name | Type | Mandatory| Description | |
| 42 | | -------- | -------------------- | ---- | ---------------------------------- | | 42 | | -------- | -------------------- | ---- | ---------------------------------- | |
| 43 | -| event | string | Yes | Name of the common event to publish. For details, see [System Common Events](./common_event/commonEventManager-definitions.md). | | 43 | +| event | string | Yes | Name of the common event to publish. For details, see [System Common Events (System API)](./common_event/commonEventManager-definitions-sys.md). | |
| 44 | -| userId | number | Yes | User ID.| | 44 | +| userId | number | Yes | ID of the user who will receive the common event.| |
| 45 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | | 45 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | |
| 46 | 46 | ||
| 47 | **Error codes** | 47 | **Error codes** |
| @@ -51,8 +51,8 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 51 | | ID| Error Message | | 51 | | ID| Error Message | |
| 52 | | -------- | ----------------------------------- | | 52 | | -------- | ----------------------------------- | |
| 53 | | 202 | Permission verification failed. A non-system application calls a system API. | | 53 | | 202 | Permission verification failed. A non-system application calls a system API. | |
| 54 | -| 1500003 | The common event sending frequency too high. | | 54 | +| 1500003 | The common event sending frequency too high.<br> Applicable versions: 20+| |
| 55 | -| 1500006 | Invalid userId. | | 55 | +| 1500006 | Invalid userId.<br> Applicable versions: 21+| |
| 56 | | 1500007 | Failed to send the message to the common event service. | | 56 | | 1500007 | Failed to send the message to the common event service. | |
| 57 | | 1500008 | Failed to initialize the common event service. | | 57 | | 1500008 | Failed to initialize the common event service. | |
| 58 | | 1500009 | Failed to obtain system parameters. | | 58 | | 1500009 | Failed to obtain system parameters. | |
| @@ -94,8 +94,8 @@ Publishes a common event to a specified user and specifies the information to be | |||
| 94 | 94 | ||
| 95 | | Name | Type | Mandatory| Description | | 95 | | Name | Type | Mandatory| Description | |
| 96 | | -------- | ---------------------- | ---- | ---------------------- | | 96 | | -------- | ---------------------- | ---- | ---------------------- | |
| 97 | -| event | string | Yes | Name of the common event to publish. For details, see [System Common Events](./common_event/commonEventManager-definitions.md). | | 97 | +| event | string | Yes | Name of the common event to publish. For details, see [System Common Events (System API)](./common_event/commonEventManager-definitions-sys.md). | |
| 98 | -| userId | number | Yes| User ID.| | 98 | +| userId | number | Yes| ID of the user who will receive the common event.| |
| 99 | | options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Properties of the common event to publish.| | 99 | | options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes | Properties of the common event to publish.| |
| 100 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | | 100 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | |
| 101 | 101 | ||
| @@ -106,8 +106,8 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 106 | | ID| Error Message | | 106 | | ID| Error Message | |
| 107 | | -------- | ----------------------------------- | | 107 | | -------- | ----------------------------------- | |
| 108 | | 202 | Permission verification failed. A non-system application calls a system API. | | 108 | | 202 | Permission verification failed. A non-system application calls a system API. | |
| 109 | -| 1500003 | The common event sending frequency too high. | | 109 | +| 1500003 | The common event sending frequency too high.<br> Applicable versions: 20+| |
| 110 | -| 1500006 | Invalid userId. | | 110 | +| 1500006 | Invalid userId.<br> Applicable versions: 21+| |
| 111 | | 1500007 | Failed to send the message to the common event service. | | 111 | | 1500007 | Failed to send the message to the common event service. | |
| 112 | | 1500008 | Failed to initialize the common event service. | | 112 | | 1500008 | Failed to initialize the common event service. | |
| 113 | | 1500009 | Failed to obtain system parameters. | | 113 | | 1500009 | Failed to obtain system parameters. | |
| @@ -118,10 +118,10 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 118 | import { BusinessError } from '@kit.BasicServicesKit'; | 118 | import { BusinessError } from '@kit.BasicServicesKit'; |
| 119 | 119 | ||
| 120 | // Information of the common event. | 120 | // Information of the common event. |
| 121 | -let options:commonEventManager.CommonEventPublishData = { | 121 | +let options: commonEventManager.CommonEventPublishData = { |
| 122 | code: 0, // Initial code of the common event. | 122 | code: 0, // Initial code of the common event. |
| 123 | - data: 'initial data',// Initial data of the common event. | 123 | + data: 'initial data', // Initial data of the common event. |
| 124 | -} | 124 | +}; |
| 125 | 125 | ||
| 126 | // Specify the user to whom the common event will be published. | 126 | // Specify the user to whom the common event will be published. |
| 127 | let userId = 100; | 127 | let userId = 100; |
| @@ -156,7 +156,7 @@ Removes a sticky common event. This API uses an asynchronous callback to return | |||
| 156 | 156 | ||
| 157 | | Name | Type | Mandatory| Description | | 157 | | Name | Type | Mandatory| Description | |
| 158 | | -------- | -------------------- | ---- | -------------------------------- | | 158 | | -------- | -------------------- | ---- | -------------------------------- | |
| 159 | -| event | string | Yes | Sticky common event to remove. For details, see [System Common Events](./common_event/commonEventManager-definitions.md). | | 159 | +| event | string | Yes | Sticky common event to remove. For details, see [System Common Events (System API)](./common_event/commonEventManager-definitions-sys.md). | |
| 160 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the sticky common event is successfully removed, **err** is **undefined**; otherwise, **err** is an error object.| | 160 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the sticky common event is successfully removed, **err** is **undefined**; otherwise, **err** is an error object.| |
| 161 | 161 | ||
| 162 | **Error codes** | 162 | **Error codes** |
| @@ -179,7 +179,7 @@ import { BusinessError } from '@kit.BasicServicesKit'; | |||
| 179 | 179 | ||
| 180 | commonEventManager.removeStickyCommonEvent('sticky_event', (err: BusinessError) => { | 180 | commonEventManager.removeStickyCommonEvent('sticky_event', (err: BusinessError) => { |
| 181 | if (err) { | 181 | if (err) { |
| 182 | - console.error(`removeStickyCommonEvent failed, errCode: ${err.code}, errMes: ${err.message}`); | 182 | + console.error(`removeStickyCommonEvent failed, errCode: ${err.code}, errMsg: ${err.message}`); |
| 183 | return; | 183 | return; |
| 184 | } | 184 | } |
| 185 | console.info(`removeStickyCommonEvent success`); | 185 | console.info(`removeStickyCommonEvent success`); |
| @@ -190,7 +190,7 @@ commonEventManager.removeStickyCommonEvent('sticky_event', (err: BusinessError) | |||
| 190 | 190 | ||
| 191 | removeStickyCommonEvent(event: string): Promise\<void> | 191 | removeStickyCommonEvent(event: string): Promise\<void> |
| 192 | 192 | ||
| 193 | -Removes a sticky common event. This API uses a promise to return the result. | 193 | +Removes a sticky common event that has been published. This API uses a promise to return the result. |
| 194 | 194 | ||
| 195 | **System capability**: SystemCapability.Notification.CommonEvent | 195 | **System capability**: SystemCapability.Notification.CommonEvent |
| 196 | 196 | ||
| @@ -230,8 +230,8 @@ import { BusinessError } from '@kit.BasicServicesKit'; | |||
| 230 | 230 | ||
| 231 | commonEventManager.removeStickyCommonEvent('sticky_event').then(() => { | 231 | commonEventManager.removeStickyCommonEvent('sticky_event').then(() => { |
| 232 | console.info(`removeStickyCommonEvent success`); | 232 | console.info(`removeStickyCommonEvent success`); |
| 233 | -}).catch ((err: BusinessError) => { | 233 | +}).catch((err: BusinessError) => { |
| 234 | - console.error(`removeStickyCommonEvent failed, errCode: ${err.code}, errMes: ${err.message}`); | 234 | + console.error(`removeStickyCommonEvent failed, errCode: ${err.code}, errMsg: ${err.message}`); |
| 235 | }); | 235 | }); |
| 236 | ``` | 236 | ``` |
| 237 | 237 | ||
| @@ -239,7 +239,7 @@ commonEventManager.removeStickyCommonEvent('sticky_event').then(() => { | |||
| 239 | 239 | ||
| 240 | setStaticSubscriberState(enable: boolean, callback: AsyncCallback\<void>): void | 240 | setStaticSubscriberState(enable: boolean, callback: AsyncCallback\<void>): void |
| 241 | 241 | ||
| 242 | -Enables or disables static subscription for an application. This API uses an asynchronous callback to return the result. | 242 | +Enables or disables static subscription for an app. This API uses an asynchronous callback to return the result. |
| 243 | 243 | ||
| 244 | **Model restriction**: This API can be used only in the stage model. | 244 | **Model restriction**: This API can be used only in the stage model. |
| 245 | 245 | ||
| @@ -251,7 +251,7 @@ Enables or disables static subscription for an application. This API uses an asy | |||
| 251 | 251 | ||
| 252 | | Name| Type | Mandatory| Description | | 252 | | Name| Type | Mandatory| Description | |
| 253 | | ------ | ------ | ---- | -------------------------- | | 253 | | ------ | ------ | ---- | -------------------------- | |
| 254 | -| enable | boolean | Yes | Whether static subscription is enabled.<br> **true**: enabled.<br>**false**: disabled.| | 254 | +| enable | boolean | Yes | Whether static subscription is enabled.<br> **true**: enabled; **false**: disabled.| |
| 255 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| | 255 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| |
| 256 | 256 | ||
| 257 | **Error codes** | 257 | **Error codes** |
| @@ -272,7 +272,7 @@ import { BusinessError } from '@kit.BasicServicesKit'; | |||
| 272 | 272 | ||
| 273 | commonEventManager.setStaticSubscriberState(true, (err: BusinessError) => { | 273 | commonEventManager.setStaticSubscriberState(true, (err: BusinessError) => { |
| 274 | if (err.code != 0) { | 274 | if (err.code != 0) { |
| 275 | - console.error(`setStaticSubscriberState failed, errCode: ${err.code}, errMes: ${err.message}`); | 275 | + console.error(`setStaticSubscriberState failed, errCode: ${err.code}, errMsg: ${err.message}`); |
| 276 | return; | 276 | return; |
| 277 | } | 277 | } |
| 278 | console.info(`setStaticSubscriberState success`); | 278 | console.info(`setStaticSubscriberState success`); |
| @@ -283,7 +283,7 @@ commonEventManager.setStaticSubscriberState(true, (err: BusinessError) => { | |||
| 283 | 283 | ||
| 284 | setStaticSubscriberState(enable: boolean): Promise\<void> | 284 | setStaticSubscriberState(enable: boolean): Promise\<void> |
| 285 | 285 | ||
| 286 | -Enables or disables static subscription for an application. This API uses a promise to return the result. | 286 | +Enables or disables static subscription for an app. This API uses a promise to return the result. |
| 287 | 287 | ||
| 288 | **Model restriction**: This API can be used only in the stage model. | 288 | **Model restriction**: This API can be used only in the stage model. |
| 289 | 289 | ||
| @@ -295,7 +295,7 @@ Enables or disables static subscription for an application. This API uses a prom | |||
| 295 | 295 | ||
| 296 | | Name| Type | Mandatory| Description | | 296 | | Name| Type | Mandatory| Description | |
| 297 | | ------ | ------ | ---- | -------------------------- | | 297 | | ------ | ------ | ---- | -------------------------- | |
| 298 | -| enable | boolean | Yes | Whether static subscription is enabled.<br> **true**: enabled.<br>**false**: disabled.| | 298 | +| enable | boolean | Yes | Whether static subscription is enabled.<br> **true**: enabled; **false**: disabled.| |
| 299 | 299 | ||
| 300 | **Return value** | 300 | **Return value** |
| 301 | 301 | ||
| @@ -322,8 +322,8 @@ import { BusinessError } from '@kit.BasicServicesKit'; | |||
| 322 | 322 | ||
| 323 | commonEventManager.setStaticSubscriberState(false).then(() => { | 323 | commonEventManager.setStaticSubscriberState(false).then(() => { |
| 324 | console.info(`setStaticSubscriberState success`); | 324 | console.info(`setStaticSubscriberState success`); |
| 325 | -}).catch ((err: BusinessError) => { | 325 | +}).catch((err: BusinessError) => { |
| 326 | - console.error(`setStaticSubscriberState failed, errCode: ${err.code}, errMes: ${err.message}`); | 326 | + console.error(`setStaticSubscriberState failed, errCode: ${err.code}, errMsg: ${err.message}`); |
| 327 | }); | 327 | }); |
| 328 | ``` | 328 | ``` |
| 329 | 329 | ||
| @@ -331,7 +331,7 @@ commonEventManager.setStaticSubscriberState(false).then(() => { | |||
| 331 | 331 | ||
| 332 | setStaticSubscriberState(enable: boolean, events?: Array\<string>): Promise\<void> | 332 | setStaticSubscriberState(enable: boolean, events?: Array\<string>): Promise\<void> |
| 333 | 333 | ||
| 334 | -Enables or disables the static subscription event for the current application and records the event name. This API uses a promise to return the result. | 334 | +Enables or disables static subscription to a common event for the current app. This API uses a promise to return the result. |
| 335 | 335 | ||
| 336 | **Model restriction**: This API can be used only in the stage model. | 336 | **Model restriction**: This API can be used only in the stage model. |
| 337 | 337 | ||
| @@ -343,8 +343,8 @@ Enables or disables the static subscription event for the current application an | |||
| 343 | 343 | ||
| 344 | | Name| Type | Mandatory| Description | | 344 | | Name| Type | Mandatory| Description | |
| 345 | | ------ | ------------- | ---- | ---------------------------------------------------- | | 345 | | ------ | ------------- | ---- | ---------------------------------------------------- | |
| 346 | -| enable | boolean | Yes | Whether static subscription is enabled.<br> **true**: enabled.<br>**false**: disabled.| | 346 | +| enable | boolean | Yes | Whether static subscription is enabled.<br> **true**: enabled; **false**: disabled.| |
| 347 | -| events | Array\<string> | No | Name of a recorded event. | | 347 | +| events | Array\<string> | No | List of common event names to be set. By default, the list is empty, indicating that the status of all common events subscribed to in static mode by the current app is to be set. | |
| 348 | 348 | ||
| 349 | **Return value** | 349 | **Return value** |
| 350 | 350 | ||
| @@ -368,10 +368,10 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 368 | ```ts | 368 | ```ts |
| 369 | import { BusinessError } from '@kit.BasicServicesKit'; | 369 | import { BusinessError } from '@kit.BasicServicesKit'; |
| 370 | 370 | ||
| 371 | -let evenName: string[] = ['usual.event.SEND_DATA']; | 371 | +let eventName: string[] = ['usual.event.SEND_DATA']; |
| 372 | -commonEventManager.setStaticSubscriberState(true, evenName).then(() => { | 372 | +commonEventManager.setStaticSubscriberState(true, eventName).then(() => { |
| 373 | - console.info(`setStaticSubscriberState success, state is ${true}`); | 373 | + console.info(`setStaticSubscriberState success`); |
| 374 | }).catch((err: BusinessError) => { | 374 | }).catch((err: BusinessError) => { |
| 375 | - console.error(`setStaticSubscriberState failed, errCode: ${err.code}, errMes: ${err.message}`); | 375 | + console.error(`setStaticSubscriberState failed, errCode: ${err.code}, errMsg: ${err.message}`); |
| 376 | }); | 376 | }); |
| 377 | ``` | 377 | ``` |
| @@ -6,7 +6,33 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -The **CommonEventManager** module provides common event capabilities to publish, subscribe to, and unsubscribe from common events. | 9 | +This module provides APIs to publish, subscribe to, and unsubscribe from common events. This module provides a system-level event notification mechanism that allows an app to send notifications to other apps that have subscribed to the event when the system status changes (such as power-on completion, battery level change, and screen on/off) or a custom service event occurs. This mechanism enables transferring information accross components and apps. |
| 10 | + | ||
| 11 | +The key concepts involved in this module are as follows: | ||
| 12 | +- System common events: preset common events published by system services or system apps, which are enumerated in **Support**. Some system common events require specific permissions for subscription. | ||
| 13 | +- Ordered common events: common events delivered to subscribers in sequence based on their priorities. The subscriber with a higher priority receives the event first and can modify the event data passed to subsequent subscribers or stop delivering the event to the subscriber with a lower priority. | ||
| 14 | + | ||
| 15 | +**APIs used in combination** | ||
| 16 | + | ||
| 17 | +The event communication of this module invovles three processes: subscription, publishing, and ordered event. The subscription process and publishing process are associated through the event name. The publisher and subscriber do not need to be aware of each other. | ||
| 18 | + | ||
| 19 | +**Subscription process: Create a subscriber, subscribe to an event, receive the event, and cancel the subscription.** | ||
| 20 | + | ||
| 21 | +1. Configure the subscriber information, declare the name of the event to be subscribed to, and set the subscription priority, publisher permission, and package name as required. | ||
| 22 | +2. Create a subscriber object using **commonEventManager.createSubscriberSync**. | ||
| 23 | +3. Subscribe to an event using **commonEventManager.subscribe**. When an event is published, use a callback to receive **CommonEventData**, and process the event data in the callback. | ||
| 24 | +4. Unsubscribe from the event using **commonEventManager.unsubscribe** when it is no longer needed. | ||
| 25 | + | ||
| 26 | +**Publishing process: Publish an event (carrying data and attributes as required).** | ||
| 27 | + | ||
| 28 | +1. Simple publishing: Publish an event by specifying only the event name using **commonEventManager.publish**. | ||
| 29 | +2. Publishing with data and attributes: Configure attributes such as code, data, parameters, and **isOrdered** using **CommonEventPublishData**, and then call **publish** to publish the event. | ||
| 30 | + | ||
| 31 | +**Ordered event process: Deliver the event by priority by collaborating with the subscriber.** | ||
| 32 | + | ||
| 33 | +1. Set **isOrdered** to **true** using **CommonEventPublishData** and call **publish** to publish ordered events. Events are delivered in sequence based on the subscriber priority. | ||
| 34 | +2. The subscriber with a higher priority receives the event first, who can modify the code and data in the callback using methods such as **setCodeAndData** for subsequent subscribers to receive. | ||
| 35 | +3. After the processing is complete, call **finishCommonEvent** to deliver the event to the subscriber with the next highest priority. To stop delivering the event, call **abortCommonEvent** to mark the event as aborted. | ||
| 10 | 36 | ||
| 11 | > **NOTE** | 37 | > **NOTE** |
| 12 | > | 38 | > |
| @@ -20,7 +46,7 @@ import { commonEventManager } from '@kit.BasicServicesKit'; | |||
| 20 | 46 | ||
| 21 | ## Support | 47 | ## Support |
| 22 | 48 | ||
| 23 | -System common events refer to events released by system services or system applications. Subscribing to these common events requires specific permissions and values. For details, see [System Common Events](./common_event/commonEventManager-definitions.md). | 49 | +System common events refer to events released by system services or system apps. Subscribing to these common events requires specific permissions and event values. For details, see [System Common Events](./common_event/commonEventManager-definitions.md). |
| 24 | 50 | ||
| 25 | ## commonEventManager.publish | 51 | ## commonEventManager.publish |
| 26 | 52 | ||
| @@ -41,11 +67,11 @@ Publishes a common event. This API uses an asynchronous callback to return the r | |||
| 41 | 67 | ||
| 42 | **Error codes** | 68 | **Error codes** |
| 43 | 69 | ||
| 44 | -For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Event Error Codes](./errorcode-CommonEventService.md). | 70 | +For details about the error codes, see [Event Error Codes](./errorcode-CommonEventService.md). |
| 45 | 71 | ||
| 46 | | ID| Error Message | | 72 | | ID| Error Message | |
| 47 | | -------- | ----------------------------------- | | 73 | | -------- | ----------------------------------- | |
| 48 | -| 1500003 | The common event sending frequency too high.<br> Applicable version: 20| | 74 | +| 1500003 | The common event sending frequency too high.<br> Applicable versions: 20+| |
| 49 | | 1500007 | Failed to send the message to the common event service. | | 75 | | 1500007 | Failed to send the message to the common event service. | |
| 50 | | 1500008 | Failed to initialize the common event service. | | 76 | | 1500008 | Failed to initialize the common event service. | |
| 51 | | 1500009 | Failed to obtain system parameters. | | 77 | | 1500009 | Failed to obtain system parameters. | |
| @@ -90,11 +116,11 @@ Publishes a common event. This API uses an asynchronous callback to return the r | |||
| 90 | 116 | ||
| 91 | **Error codes** | 117 | **Error codes** |
| 92 | 118 | ||
| 93 | -For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Event Error Codes](./errorcode-CommonEventService.md). | 119 | +For details about the error codes, see [Event Error Codes](./errorcode-CommonEventService.md). |
| 94 | 120 | ||
| 95 | | ID| Error Message | | 121 | | ID| Error Message | |
| 96 | | -------- | ----------------------------------- | | 122 | | -------- | ----------------------------------- | |
| 97 | -| 1500003 | The common event sending frequency too high.<br> Applicable version: 20| | 123 | +| 1500003 | The common event sending frequency too high.<br> Applicable versions: 20+| |
| 98 | | 1500007 | Failed to send the message to the common event service. | | 124 | | 1500007 | Failed to send the message to the common event service. | |
| 99 | | 1500008 | Failed to initialize the common event service. | | 125 | | 1500008 | Failed to initialize the common event service. | |
| 100 | | 1500009 | Failed to obtain system parameters. | | 126 | | 1500009 | Failed to obtain system parameters. | |
| @@ -109,7 +135,7 @@ let options: commonEventManager.CommonEventPublishData = { | |||
| 109 | code: 0, | 135 | code: 0, |
| 110 | data: 'initial data', | 136 | data: 'initial data', |
| 111 | isOrdered: true // The common event is an ordered one. | 137 | isOrdered: true // The common event is an ordered one. |
| 112 | -} | 138 | +}; |
| 113 | 139 | ||
| 114 | // Publish a common event. | 140 | // Publish a common event. |
| 115 | try { | 141 | try { |
| @@ -141,7 +167,7 @@ Creates a subscriber. This API uses an asynchronous callback to return the resul | |||
| 141 | | Name | Type | Mandatory| Description | | 167 | | Name | Type | Mandatory| Description | |
| 142 | | ------------- | ------------------------------------------------------------ | ---- | -------------------------- | | 168 | | ------------- | ------------------------------------------------------------ | ---- | -------------------------- | |
| 143 | | subscribeInfo | [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | Yes | Subscriber information. | | 169 | | subscribeInfo | [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | Yes | Subscriber information. | |
| 144 | -| callback | AsyncCallback\<[CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md#commoneventsubscriber-1)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| | 170 | +| callback | AsyncCallback\<[CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md#commoneventsubscriber-1)> | Yes | Callback used to receive the created subscriber object. When a common event subscriber is successfully created, **err** is **undefined** and **data** is the **CommonEventSubscriber** object created. Otherwise, **err** is an error object.| |
| 145 | 171 | ||
| 146 | **Error codes** | 172 | **Error codes** |
| 147 | 173 | ||
| @@ -167,7 +193,7 @@ let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { | |||
| 167 | try { | 193 | try { |
| 168 | commonEventManager.createSubscriber(subscribeInfo, | 194 | commonEventManager.createSubscriber(subscribeInfo, |
| 169 | (err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) => { | 195 | (err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) => { |
| 170 | - if(!err) { | 196 | + if (!err) { |
| 171 | console.info(`Succeeded in creating subscriber.`); | 197 | console.info(`Succeeded in creating subscriber.`); |
| 172 | subscriber = commonEventSubscriber; | 198 | subscriber = commonEventSubscriber; |
| 173 | return; | 199 | return; |
| @@ -233,7 +259,7 @@ commonEventManager.createSubscriber(subscribeInfo).then((commonEventSubscriber: | |||
| 233 | 259 | ||
| 234 | createSubscriberSync(subscribeInfo: CommonEventSubscribeInfo): CommonEventSubscriber | 260 | createSubscriberSync(subscribeInfo: CommonEventSubscribeInfo): CommonEventSubscriber |
| 235 | 261 | ||
| 236 | -Creates a subscriber. The API returns the result synchronously. | 262 | +Creates a subscriber synchronously. |
| 237 | 263 | ||
| 238 | **Atomic service API**: This API can be used in atomic services since API version 11. | 264 | **Atomic service API**: This API can be used in atomic services since API version 11. |
| 239 | 265 | ||
| @@ -293,7 +319,7 @@ Subscribes to a common event. This API uses an asynchronous callback to return t | |||
| 293 | | Name | Type | Mandatory| Description | | 319 | | Name | Type | Mandatory| Description | |
| 294 | | ---------- | ---------------------------------------------------- | ---- | -------------------------------- | | 320 | | ---------- | ---------------------------------------------------- | ---- | -------------------------------- | |
| 295 | | subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md#commoneventsubscriber-1) | Yes | Subscriber object. | | 321 | | subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md#commoneventsubscriber-1) | Yes | Subscriber object. | |
| 296 | -| callback | AsyncCallback\<[CommonEventData](./js-apis-inner-commonEvent-commonEventData.md)> | Yes | Callback used to return the result. if the operation is successful; otherwise, **err** is an error object.| | 322 | +| callback | AsyncCallback\<[CommonEventData](./js-apis-inner-commonEvent-commonEventData.md)> | Yes | Callback used to return the result. When a common event is successfully subscribed to, the common event data is returned by **data** when the event is triggered. If the subscription fails, **err** is an error object.| |
| 297 | 323 | ||
| 298 | **Error codes** | 324 | **Error codes** |
| 299 | 325 | ||
| @@ -301,10 +327,10 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 301 | 327 | ||
| 302 | | ID| Error Message | | 328 | | ID| Error Message | |
| 303 | | -------- | ----------------------------------- | | 329 | | -------- | ----------------------------------- | |
| 304 | -| 801 | capability not supported. | | 330 | +| 801 | Capability not supported. | |
| 305 | | 1500007 | Failed to send the message to the common event service. | | 331 | | 1500007 | Failed to send the message to the common event service. | |
| 306 | | 1500008 | Failed to initialize the common event service. | | 332 | | 1500008 | Failed to initialize the common event service. | |
| 307 | -| 1500010 | The count of subscriber exceed system specification. <br> Applicable version: 20| | 333 | +| 1500010 | The count of subscriber exceed system specification. <br> Applicable versions: 20+| |
| 308 | 334 | ||
| 309 | **Example** | 335 | **Example** |
| 310 | 336 | ||
| @@ -322,7 +348,7 @@ let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { | |||
| 322 | try { | 348 | try { |
| 323 | commonEventManager.createSubscriber(subscribeInfo, | 349 | commonEventManager.createSubscriber(subscribeInfo, |
| 324 | (err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) => { | 350 | (err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) => { |
| 325 | - if(!err) { | 351 | + if (!err) { |
| 326 | console.info(`Succeeded in creating subscriber.`); | 352 | console.info(`Succeeded in creating subscriber.`); |
| 327 | subscriber = commonEventSubscriber; | 353 | subscriber = commonEventSubscriber; |
| 328 | // Subscribe to a common event. | 354 | // Subscribe to a common event. |
| @@ -363,7 +389,7 @@ Unsubscribes from a common event. This API uses an asynchronous callback to retu | |||
| 363 | | Name | Type | Mandatory| Description | | 389 | | Name | Type | Mandatory| Description | |
| 364 | | ---------- | ----------------------------------------------- | ---- | ------------------------ | | 390 | | ---------- | ----------------------------------------------- | ---- | ------------------------ | |
| 365 | | subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md#commoneventsubscriber-1) | Yes | Subscriber object. | | 391 | | subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md#commoneventsubscriber-1) | Yes | Subscriber object. | |
| 366 | -| callback | AsyncCallback\<void> | No | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| | 392 | +| callback | AsyncCallback\<void> | No | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. If this parameter is not passed, the subscription is canceled by default and no result is returned.| |
| 367 | 393 | ||
| 368 | **Error codes** | 394 | **Error codes** |
| 369 | 395 | ||
| @@ -372,7 +398,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 372 | | ID| Error Message | | 398 | | ID| Error Message | |
| 373 | | -------- | ----------------------------------- | | 399 | | -------- | ----------------------------------- | |
| 374 | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 400 | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | |
| 375 | -| 801 | capability not supported. | | 401 | +| 801 | Capability not supported. | |
| 376 | | 1500007 | Failed to send the message to the common event service. | | 402 | | 1500007 | Failed to send the message to the common event service. | |
| 377 | | 1500008 | Failed to initialize the common event service. | | 403 | | 1500008 | Failed to initialize the common event service. | |
| 378 | 404 | ||
| @@ -392,7 +418,7 @@ let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { | |||
| 392 | try { | 418 | try { |
| 393 | commonEventManager.createSubscriber(subscribeInfo, | 419 | commonEventManager.createSubscriber(subscribeInfo, |
| 394 | (err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) => { | 420 | (err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) => { |
| 395 | - if(!err) { | 421 | + if (!err) { |
| 396 | console.info(`Succeeded in creating subscriber.`); | 422 | console.info(`Succeeded in creating subscriber.`); |
| 397 | subscriber = commonEventSubscriber; | 423 | subscriber = commonEventSubscriber; |
| 398 | // Subscribe to a common event. | 424 | // Subscribe to a common event. |
| @@ -463,7 +489,7 @@ Subscribes to a common event. This API uses a promise to return the result. | |||
| 463 | 489 | ||
| 464 | For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Event Error Codes](./errorcode-CommonEventService.md). | 490 | For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Event Error Codes](./errorcode-CommonEventService.md). |
| 465 | 491 | ||
| 466 | -| ID| Error Message | | 492 | +| ID| Error Message | |
| 467 | | -------- | ----------------------------------- | | 493 | | -------- | ----------------------------------- | |
| 468 | | 801 | Capability not supported. | | 494 | | 801 | Capability not supported. | |
| 469 | | 1500007 | Failed to send the message to the common event service. | | 495 | | 1500007 | Failed to send the message to the common event service. | |
| @@ -479,7 +505,7 @@ import { BusinessError } from '@kit.BasicServicesKit'; | |||
| 479 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; | 505 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; |
| 480 | // Subscriber information. | 506 | // Subscriber information. |
| 481 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { | 507 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { |
| 482 | - events: ["event"] | 508 | + events: ['event'] |
| 483 | }; | 509 | }; |
| 484 | 510 | ||
| 485 | // Create a subscriber. | 511 | // Create a subscriber. |
| @@ -494,9 +520,9 @@ try { | |||
| 494 | // Subscribe to a common event. | 520 | // Subscribe to a common event. |
| 495 | try { | 521 | try { |
| 496 | commonEventManager.subscribeToEvent(subscriber, (data: commonEventManager.CommonEventData) => { | 522 | commonEventManager.subscribeToEvent(subscriber, (data: commonEventManager.CommonEventData) => { |
| 497 | - console.info(`Succeeded to receive common event, data is ` + JSON.stringify(data)); | 523 | + console.info(`Succeeded to receive common event, data is ${JSON.stringify(data)}`); |
| 498 | }).then(() => { | 524 | }).then(() => { |
| 499 | - console.info(`Succeeded to subscribe.`); | 525 | + console.info(`Succeeded in subscribing.`); |
| 500 | }).catch((err: BusinessError) => { | 526 | }).catch((err: BusinessError) => { |
| 501 | console.error(`Failed to subscribe. Code is ${err.code}, message is ${err.message}`); | 527 | console.error(`Failed to subscribe. Code is ${err.code}, message is ${err.message}`); |
| 502 | }); | 528 | }); |
| @@ -544,7 +570,7 @@ Describes the subscriber of a common event. | |||
| 544 | 570 | ||
| 545 | type CommonEventSubscribeInfo = _CommonEventSubscribeInfo | 571 | type CommonEventSubscribeInfo = _CommonEventSubscribeInfo |
| 546 | 572 | ||
| 547 | -Describes the information about a subscriber. | 573 | +Describes information about a common event subscriber. |
| 548 | 574 | ||
| 549 | **Atomic service API**: This API can be used in atomic services since API version 11. | 575 | **Atomic service API**: This API can be used in atomic services since API version 11. |
| 550 | 576 | ||
| @@ -6,7 +6,20 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -The **Emitter** module provides the capabilities of sending and processing inter- or intra-thread events in a process. You can use the APIs of this module to subscribe to an event in persistent or one-shot manner, unsubscribe from an event, or emit an event to the event queue. | 9 | +This module provides the capability of sending and processing events between threads in a process or within a thread. You can use the APIs of this module to subscribe to events (continuous subscription or one-shot subscription), cancel event subscription, send events to the event queue, and query the number of subscribed events. In this way, event communication between different threads in the same process and within the same thread can be implemented. |
| 10 | + | ||
| 11 | +Two event processing entries are provided. You can select one based on the isolation requirements: | ||
| 12 | + | ||
| 13 | +- **Namespace APIs** (**on**, **once**, **off**, **emit**, and **getListenerCount** in the **emitter** namespace): provide global event subscription and publishing capabilities within a process. This entry works based on the global event queue. Any thread in the same process can subscribe to and publish events. These APIs are suitable for cross-thread event communication. | ||
| 14 | +- **Instance APIs** (**Emitter** class): provide the event subscription and publishing capabilities within the same **Emitter** instance. Different **Emitter** instances are isolated from each other. You can create multiple independent event communication channels when events need to be isolated or grouped by instance. | ||
| 15 | + | ||
| 16 | +**APIs used in combination** | ||
| 17 | + | ||
| 18 | +The event communication of this module follows the calling sequence of subscription, publishing, processing , and unsubscription. For both namespace and instance APIs, you need to subscribe to an event first, and then another thread or the same thread publishes the event. The callback is executed after the event is received. When the event is no longer needed, unsubscribe from the event to release resources. In addition, event subscription has a lifecycle. Pay attention to resource management: | ||
| 19 | + | ||
| 20 | +- **Continuous subscription** (**on**): The subscription remains valid until **off** is called to cancel subscription. If the subscription is not canceled, it will be retained. | ||
| 21 | +- **One-shot subscription** (**once**): The subscription is automatically canceled after the event is received for the first time and the callback is executed. You do not need to manually call **off**. | ||
| 22 | +- **Time for unsubscription**: After the subscription is canceled by calling **off**, the events that have been published through **emit** but have not been executed are also canceled and no callback is triggered. Note that when canceling a specified callback, you need to pass the corresponding callback function. If no callback is specified, all subscriptions to the event are canceled. | ||
| 10 | 23 | ||
| 11 | > **NOTE** | 24 | > **NOTE** |
| 12 | > | 25 | > |
| @@ -46,15 +59,15 @@ let innerEvent: emitter.InnerEvent = { | |||
| 46 | 59 | ||
| 47 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 60 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 48 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 61 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 49 | -} | 62 | +}; |
| 50 | 63 | ||
| 51 | -// Execute the callback after receiving the event whose eventId is 1. | 64 | +// Execute the callback after receiving the event whose ID is 1. |
| 52 | emitter.on(innerEvent, callback); | 65 | emitter.on(innerEvent, callback); |
| 53 | ``` | 66 | ``` |
| 54 | 67 | ||
| 55 | ## emitter.on<sup>11+</sup> | 68 | ## emitter.on<sup>11+</sup> |
| 56 | 69 | ||
| 57 | -on(eventId: string, callback: Callback\<EventData\>): void | 70 | +on(eventId: string, callback: Callback\<EventData\>): void |
| 58 | 71 | ||
| 59 | Subscribes to an event in persistent manner and executes a callback after the event is received. | 72 | Subscribes to an event in persistent manner and executes a callback after the event is received. |
| 60 | 73 | ||
| @@ -66,7 +79,7 @@ Subscribes to an event in persistent manner and executes a callback after the ev | |||
| 66 | 79 | ||
| 67 | | Name | Type | Mandatory| Description | | 80 | | Name | Type | Mandatory| Description | |
| 68 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 81 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 69 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 82 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 70 | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to be invoked when the event is received.| | 83 | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to be invoked when the event is received.| |
| 71 | 84 | ||
| 72 | **Example** | 85 | **Example** |
| @@ -76,14 +89,14 @@ import { Callback } from '@kit.BasicServicesKit'; | |||
| 76 | 89 | ||
| 77 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 90 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 78 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 91 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 79 | -} | 92 | +}; |
| 80 | -// Execute the callback after receiving the event whose event ID is eventId. | 93 | +// Execute the callback after receiving the event whose ID is eventId. |
| 81 | -emitter.on(`eventId`, callback); | 94 | +emitter.on('eventId', callback); |
| 82 | ``` | 95 | ``` |
| 83 | 96 | ||
| 84 | ## emitter.on<sup>12+</sup> | 97 | ## emitter.on<sup>12+</sup> |
| 85 | 98 | ||
| 86 | -on<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void | 99 | +on<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void |
| 87 | 100 | ||
| 88 | Subscribes to an event in persistent manner and executes a callback after the event is received. | 101 | Subscribes to an event in persistent manner and executes a callback after the event is received. |
| 89 | 102 | ||
| @@ -95,7 +108,7 @@ Subscribes to an event in persistent manner and executes a callback after the ev | |||
| 95 | 108 | ||
| 96 | | Name | Type | Mandatory| Description | | 109 | | Name | Type | Mandatory| Description | |
| 97 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 110 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 98 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 111 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 99 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | Yes | Callback to be invoked when the event is received.| | 112 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | Yes | Callback to be invoked when the event is received.| |
| 100 | 113 | ||
| 101 | **Example** | 114 | **Example** |
| @@ -119,9 +132,9 @@ let callback: Callback<emitter.GenericEventData<Sample>> = (eventData: emitter.G | |||
| 119 | if (eventData?.data instanceof Sample) { | 132 | if (eventData?.data instanceof Sample) { |
| 120 | eventData?.data?.printCount(); | 133 | eventData?.data?.printCount(); |
| 121 | } | 134 | } |
| 122 | -} | 135 | +}; |
| 123 | // Execute the callback after receiving the event whose event ID is eventId. | 136 | // Execute the callback after receiving the event whose event ID is eventId. |
| 124 | -emitter.on("eventId", callback); | 137 | +emitter.on('eventId', callback); |
| 125 | ``` | 138 | ``` |
| 126 | 139 | ||
| 127 | ## emitter.once | 140 | ## emitter.once |
| @@ -152,8 +165,8 @@ let innerEvent: emitter.InnerEvent = { | |||
| 152 | 165 | ||
| 153 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 166 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 154 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 167 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 155 | -} | 168 | +}; |
| 156 | -// Execute the callback after receiving the event whose eventId is 1. | 169 | +// Execute the callback after receiving the event whose ID is 1. |
| 157 | emitter.once(innerEvent, callback); | 170 | emitter.once(innerEvent, callback); |
| 158 | ``` | 171 | ``` |
| 159 | 172 | ||
| @@ -171,7 +184,7 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve | |||
| 171 | 184 | ||
| 172 | | Name | Type | Mandatory| Description | | 185 | | Name | Type | Mandatory| Description | |
| 173 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 186 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 174 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 187 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 175 | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to be invoked when the event is received.| | 188 | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to be invoked when the event is received.| |
| 176 | 189 | ||
| 177 | **Example** | 190 | **Example** |
| @@ -181,9 +194,9 @@ import { Callback } from '@kit.BasicServicesKit'; | |||
| 181 | 194 | ||
| 182 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 195 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 183 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 196 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 184 | -} | 197 | +}; |
| 185 | // Execute the callback after receiving the event whose event ID is eventId. | 198 | // Execute the callback after receiving the event whose event ID is eventId. |
| 186 | -emitter.once("eventId", callback); | 199 | +emitter.once('eventId', callback); |
| 187 | ``` | 200 | ``` |
| 188 | 201 | ||
| 189 | ## emitter.once<sup>12+</sup> | 202 | ## emitter.once<sup>12+</sup> |
| @@ -200,7 +213,7 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve | |||
| 200 | 213 | ||
| 201 | | Name | Type | Mandatory| Description | | 214 | | Name | Type | Mandatory| Description | |
| 202 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 215 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 203 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 216 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 204 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | Yes | Callback to be invoked when the event is received.| | 217 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | Yes | Callback to be invoked when the event is received.| |
| 205 | 218 | ||
| 206 | **Example** | 219 | **Example** |
| @@ -224,9 +237,9 @@ let callback: Callback<emitter.GenericEventData<Sample>> = (eventData: emitter.G | |||
| 224 | if (eventData?.data instanceof Sample) { | 237 | if (eventData?.data instanceof Sample) { |
| 225 | eventData?.data?.printCount(); | 238 | eventData?.data?.printCount(); |
| 226 | } | 239 | } |
| 227 | -} | 240 | +}; |
| 228 | // Execute the callback after receiving the event whose event ID is eventId. | 241 | // Execute the callback after receiving the event whose event ID is eventId. |
| 229 | -emitter.once("eventId", callback); | 242 | +emitter.once('eventId', callback); |
| 230 | ``` | 243 | ``` |
| 231 | 244 | ||
| 232 | ## emitter.off | 245 | ## emitter.off |
| @@ -270,7 +283,7 @@ After this API is used to unsubscribe from an event, the event that has been pub | |||
| 270 | 283 | ||
| 271 | | Name | Type | Mandatory| Description | | 284 | | Name | Type | Mandatory| Description | |
| 272 | | ------- | ------ | ---- | -------- | | 285 | | ------- | ------ | ---- | -------- | |
| 273 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty.| | 286 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated.| |
| 274 | 287 | ||
| 275 | **Example** | 288 | **Example** |
| 276 | 289 | ||
| @@ -296,7 +309,7 @@ After this API is used to unsubscribe from an event, the event that has been pub | |||
| 296 | | Name | Type | Mandatory| Description | | 309 | | Name | Type | Mandatory| Description | |
| 297 | | ------- | ------ | ---- | ------ | | 310 | | ------- | ------ | ---- | ------ | |
| 298 | | eventId | number | Yes | Event ID.| | 311 | | eventId | number | Yes | Event ID.| |
| 299 | -| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to unregister. | | 312 | +| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to unregister, which must be the same as the callback used during registration. | |
| 300 | 313 | ||
| 301 | **Example** | 314 | **Example** |
| 302 | 315 | ||
| @@ -305,7 +318,7 @@ import { Callback } from '@kit.BasicServicesKit'; | |||
| 305 | 318 | ||
| 306 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 319 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 307 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 320 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 308 | -} | 321 | +}; |
| 309 | // Unregister all callbacks for events whose **eventId** is **1**. The callback object must be the object used during registration. | 322 | // Unregister all callbacks for events whose **eventId** is **1**. The callback object must be the object used during registration. |
| 310 | // If the callback has not been registered, no processing is performed. | 323 | // If the callback has not been registered, no processing is performed. |
| 311 | emitter.off(1, callback); | 324 | emitter.off(1, callback); |
| @@ -327,8 +340,8 @@ After this API is used to unsubscribe from an event, the event that has been pub | |||
| 327 | 340 | ||
| 328 | | Name | Type | Mandatory| Description | | 341 | | Name | Type | Mandatory| Description | |
| 329 | | -------- | ----------------------------------- | ---- | -------------------------- | | 342 | | -------- | ----------------------------------- | ---- | -------------------------- | |
| 330 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 343 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 331 | -| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to unregister.| | 344 | +| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to unregister, which must be the same as the callback used during registration.| |
| 332 | 345 | ||
| 333 | **Example** | 346 | **Example** |
| 334 | 347 | ||
| @@ -337,7 +350,7 @@ import { Callback } from '@kit.BasicServicesKit'; | |||
| 337 | 350 | ||
| 338 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 351 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 339 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 352 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 340 | -} | 353 | +}; |
| 341 | // Unregister all callbacks for events whose **eventId** is **eventId1**. The callback object must be the object used during registration. | 354 | // Unregister all callbacks for events whose **eventId** is **eventId1**. The callback object must be the object used during registration. |
| 342 | // If the callback has not been registered, no processing is performed. | 355 | // If the callback has not been registered, no processing is performed. |
| 343 | emitter.off("eventId1", callback); | 356 | emitter.off("eventId1", callback); |
| @@ -359,8 +372,8 @@ After this API is used to unsubscribe from an event, the event that has been pub | |||
| 359 | 372 | ||
| 360 | | Name | Type | Mandatory| Description | | 373 | | Name | Type | Mandatory| Description | |
| 361 | | -------- | ----------------------------------- | ---- | -------------------------- | | 374 | | -------- | ----------------------------------- | ---- | -------------------------- | |
| 362 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 375 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 363 | -| callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | Yes | Callback to unregister.| | 376 | +| callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | Yes | Callback to unregister, which must be the same as the callback used during registration.| |
| 364 | 377 | ||
| 365 | **Example** | 378 | **Example** |
| 366 | 379 | ||
| @@ -383,7 +396,7 @@ let callback: Callback<emitter.GenericEventData<Sample>> = (eventData: emitter.G | |||
| 383 | if (eventData?.data instanceof Sample) { | 396 | if (eventData?.data instanceof Sample) { |
| 384 | eventData?.data?.printCount(); | 397 | eventData?.data?.printCount(); |
| 385 | } | 398 | } |
| 386 | -} | 399 | +}; |
| 387 | // Unregister all callbacks for events whose **eventId** is **eventId1**. The callback object must be the object used during registration. | 400 | // Unregister all callbacks for events whose **eventId** is **eventId1**. The callback object must be the object used during registration. |
| 388 | // If the callback has not been registered, no processing is performed. | 401 | // If the callback has not been registered, no processing is performed. |
| 389 | emitter.off("eventId1", callback); | 402 | emitter.off("eventId1", callback); |
| @@ -446,7 +459,7 @@ After an event is published using this API, the event may not be executed immedi | |||
| 446 | 459 | ||
| 447 | | Name | Type | Mandatory| Description | | 460 | | Name | Type | Mandatory| Description | |
| 448 | | ------- | ----------------------- | ---- | ---------------- | | 461 | | ------- | ----------------------- | ---- | ---------------- | |
| 449 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 462 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 450 | | data | [EventData](#eventdata) | No | Data carried by the event. This parameter is left empty by default.| | 463 | | data | [EventData](#eventdata) | No | Data carried by the event. This parameter is left empty by default.| |
| 451 | 464 | ||
| 452 | **Example** | 465 | **Example** |
| @@ -454,12 +467,12 @@ After an event is published using this API, the event may not be executed immedi | |||
| 454 | ```ts | 467 | ```ts |
| 455 | let eventData: emitter.EventData = { | 468 | let eventData: emitter.EventData = { |
| 456 | data: { | 469 | data: { |
| 457 | - "content": "content", | 470 | + "content": "content", |
| 458 | - "id": 1, | 471 | + "id": 1, |
| 459 | } | 472 | } |
| 460 | }; | 473 | }; |
| 461 | 474 | ||
| 462 | -emitter.emit("eventId", eventData); | 475 | +emitter.emit('eventId', eventData); |
| 463 | ``` | 476 | ``` |
| 464 | 477 | ||
| 465 | ## emitter.emit<sup>12+</sup> | 478 | ## emitter.emit<sup>12+</sup> |
| @@ -480,7 +493,7 @@ After an event is published using this API, the event may not be executed immedi | |||
| 480 | 493 | ||
| 481 | | Name | Type | Mandatory| Description | | 494 | | Name | Type | Mandatory| Description | |
| 482 | | ------- | ----------------------- | ---- | ---------------- | | 495 | | ------- | ----------------------- | ---- | ---------------- | |
| 483 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 496 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 484 | | data | [GenericEventData<T\>](#genericeventdatat12) | No | Data carried by the event. This parameter is left empty by default.| | 497 | | data | [GenericEventData<T\>](#genericeventdatat12) | No | Data carried by the event. This parameter is left empty by default.| |
| 485 | 498 | ||
| 486 | **Example** | 499 | **Example** |
| @@ -500,7 +513,7 @@ class Sample { | |||
| 500 | let eventData: emitter.GenericEventData<Sample> = { | 513 | let eventData: emitter.GenericEventData<Sample> = { |
| 501 | data: new Sample() | 514 | data: new Sample() |
| 502 | }; | 515 | }; |
| 503 | -emitter.emit("eventId", eventData); | 516 | +emitter.emit('eventId', eventData); |
| 504 | ``` | 517 | ``` |
| 505 | 518 | ||
| 506 | ## emitter.emit<sup>11+</sup> | 519 | ## emitter.emit<sup>11+</sup> |
| @@ -521,7 +534,7 @@ After an event is published using this API, the event may not be executed immedi | |||
| 521 | 534 | ||
| 522 | | Name | Type | Mandatory| Description | | 535 | | Name | Type | Mandatory| Description | |
| 523 | | ------- | ----------------------- | ---- | ---------------- | | 536 | | ------- | ----------------------- | ---- | ---------------- | |
| 524 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 537 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 525 | | options | [Options](#options11) | Yes | Event emit priority. | | 538 | | options | [Options](#options11) | Yes | Event emit priority. | |
| 526 | | data | [EventData](#eventdata) | No | Data carried by the event. This parameter is left empty by default.| | 539 | | data | [EventData](#eventdata) | No | Data carried by the event. This parameter is left empty by default.| |
| 527 | 540 | ||
| @@ -539,7 +552,7 @@ let options: emitter.Options = { | |||
| 539 | priority: emitter.EventPriority.HIGH | 552 | priority: emitter.EventPriority.HIGH |
| 540 | }; | 553 | }; |
| 541 | 554 | ||
| 542 | -emitter.emit("eventId", options, eventData); | 555 | +emitter.emit('eventId', options, eventData); |
| 543 | ``` | 556 | ``` |
| 544 | 557 | ||
| 545 | ## emitter.emit<sup>12+</sup> | 558 | ## emitter.emit<sup>12+</sup> |
| @@ -560,7 +573,7 @@ After an event is published using this API, the event may not be executed immedi | |||
| 560 | 573 | ||
| 561 | | Name | Type | Mandatory| Description | | 574 | | Name | Type | Mandatory| Description | |
| 562 | | ------- | ----------------------- | ---- | ---------------- | | 575 | | ------- | ----------------------- | ---- | ---------------- | |
| 563 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 576 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 564 | | options | [Options](#options11) | Yes | Event emit priority. | | 577 | | options | [Options](#options11) | Yes | Event emit priority. | |
| 565 | | data | [GenericEventData<T\>](#genericeventdatat12) | No | Data carried by the event. This parameter is left empty by default.| | 578 | | data | [GenericEventData<T\>](#genericeventdatat12) | No | Data carried by the event. This parameter is left empty by default.| |
| 566 | 579 | ||
| @@ -585,7 +598,7 @@ let eventData: emitter.GenericEventData<Sample> = { | |||
| 585 | data: new Sample() | 598 | data: new Sample() |
| 586 | }; | 599 | }; |
| 587 | 600 | ||
| 588 | -emitter.emit("eventId", options, eventData); | 601 | +emitter.emit('eventId', options, eventData); |
| 589 | ``` | 602 | ``` |
| 590 | 603 | ||
| 591 | ## emitter.getListenerCount<sup>11+</sup> | 604 | ## emitter.getListenerCount<sup>11+</sup> |
| @@ -602,9 +615,9 @@ Obtains the number of subscriptions to a specified event. | |||
| 602 | 615 | ||
| 603 | | Name | Type | Mandatory| Description | | 616 | | Name | Type | Mandatory| Description | |
| 604 | | ------- | -------------- | ---- | -------- | | 617 | | ------- | -------------- | ---- | -------- | |
| 605 | -| eventId | number \| string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty.| | 618 | +| eventId | number \| string | Yes | Event ID,<br> which cannot be empty or exceed 10,240 bytes. Excess content will be truncated.| |
| 606 | 619 | ||
| 607 | -**Returns** | 620 | +**Return value** |
| 608 | 621 | ||
| 609 | | Type | Description | | 622 | | Type | Description | |
| 610 | | ------- |------------| | 623 | | ------- |------------| |
| @@ -614,7 +627,7 @@ Obtains the number of subscriptions to a specified event. | |||
| 614 | **Example** | 627 | **Example** |
| 615 | 628 | ||
| 616 | ```ts | 629 | ```ts |
| 617 | -let count: number = emitter.getListenerCount("eventId"); | 630 | +let count: number = emitter.getListenerCount('eventId'); |
| 618 | ``` | 631 | ``` |
| 619 | 632 | ||
| 620 | ## EventPriority | 633 | ## EventPriority |
| @@ -655,7 +668,7 @@ Describes data carried by the emitted event. | |||
| 655 | 668 | ||
| 656 | | Name| Type | Read Only| Optional| Description | | 669 | | Name| Type | Read Only| Optional| Description | |
| 657 | | ---- | ------------------ | ---- | ---- | -------------- | | 670 | | ---- | ------------------ | ---- | ---- | -------------- | |
| 658 | -| data | { [key: string]: any } | No | Yes | Data carried by the emitted event. The value can be in any of the following types: Array, ArrayBuffer, Boolean, DataView, Date, Error, Map, Number, Object, Primitive (except symbol), RegExp, Set, String, and TypedArray. The maximum data size is 16 MB.| | 671 | +| data | { [key: string]: any } | No | Yes | Data carried by the emitted event. The value can be in any of the following types: Array, ArrayBuffer, Boolean, DataView, Date, Error, Map, Number, Object, Primitive (except symbol), RegExp, Set, String, and TypedArray. The maximum data size is 16 MB. If the data size exceeds the limit, the event fails to be emitted.| |
| 659 | 672 | ||
| 660 | ## Options<sup>11+</sup> | 673 | ## Options<sup>11+</sup> |
| 661 | 674 | ||
| @@ -679,12 +692,12 @@ Describes the generic data carried by the emitted event. | |||
| 679 | 692 | ||
| 680 | | Name | Type | Read Only| Optional| Description | | 693 | | Name | Type | Read Only| Optional| Description | |
| 681 | | -------- | ------------------------------- | ---- | ---- | -------------- | | 694 | | -------- | ------------------------------- | ---- | ---- | -------------- | |
| 682 | -| data | T | No | Yes | Data carried by the emitted event. **T**: generic type.| | 695 | +| data | T | No | Yes | Data carried by the emitted event. **T** represents a generic type, which can be customized based on service requirements.| |
| 683 | 696 | ||
| 684 | 697 | ||
| 685 | ## Emitter<sup>22+</sup> | 698 | ## Emitter<sup>22+</sup> |
| 686 | 699 | ||
| 687 | -This module provides the capabilities of sending and processing inter- or intra-thread events in a process of the same Emitter instance. You can use the following APIs to subscribe to an event in persistent or one-shot manner, unsubscribe from an event, or emit an event to the event queue. | 700 | +This module provides the capabilities of sending and processing inter- or intra-thread events in a process of the same **Emitter** instance. You can use the following APIs to subscribe to an event in persistent or one-shot manner, cancel the subscription, or emit an event to the event queue. This module is applicable when inter-thread communication and event management are required based on independent instances. Different **Emitter** instances are isolated from each other. |
| 688 | 701 | ||
| 689 | **Atomic service API**: This API can be used in atomic services since API version 22. | 702 | **Atomic service API**: This API can be used in atomic services since API version 22. |
| 690 | 703 | ||
| @@ -709,7 +722,7 @@ let emitter1: emitter.Emitter = new emitter.Emitter(); | |||
| 709 | 722 | ||
| 710 | ### on<sup>22+</sup> | 723 | ### on<sup>22+</sup> |
| 711 | 724 | ||
| 712 | -on(eventId: string, callback: Callback\<EventData\>): void | 725 | +on(eventId: string, callback: Callback\<EventData\>): void |
| 713 | 726 | ||
| 714 | Subscribes to an event specified by the Emitter instance in persistent manner and executes a callback after the event is received. | 727 | Subscribes to an event specified by the Emitter instance in persistent manner and executes a callback after the event is received. |
| 715 | 728 | ||
| @@ -721,7 +734,7 @@ Subscribes to an event specified by the Emitter instance in persistent manner an | |||
| 721 | 734 | ||
| 722 | | Name | Type | Mandatory| Description | | 735 | | Name | Type | Mandatory| Description | |
| 723 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 736 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 724 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 737 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 725 | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to be invoked when the event is received.| | 738 | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to be invoked when the event is received.| |
| 726 | 739 | ||
| 727 | **Example** | 740 | **Example** |
| @@ -733,14 +746,14 @@ let emitter1: emitter.Emitter = new emitter.Emitter(); | |||
| 733 | 746 | ||
| 734 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 747 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 735 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 748 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 736 | -} | 749 | +}; |
| 737 | 750 | ||
| 738 | -emitter1.on(`eventId`, callback); | 751 | +emitter1.on('eventId', callback); |
| 739 | ``` | 752 | ``` |
| 740 | 753 | ||
| 741 | ### on<sup>22+</sup> | 754 | ### on<sup>22+</sup> |
| 742 | 755 | ||
| 743 | -on<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void | 756 | +on<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void |
| 744 | 757 | ||
| 745 | Subscribes to an event specified by the Emitter instance in persistent manner and executes a callback after the event is received. | 758 | Subscribes to an event specified by the Emitter instance in persistent manner and executes a callback after the event is received. |
| 746 | 759 | ||
| @@ -752,7 +765,7 @@ Subscribes to an event specified by the Emitter instance in persistent manner an | |||
| 752 | 765 | ||
| 753 | | Name | Type | Mandatory| Description | | 766 | | Name | Type | Mandatory| Description | |
| 754 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 767 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 755 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 768 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 756 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | Yes | Callback to be invoked when the event is received.| | 769 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | Yes | Callback to be invoked when the event is received.| |
| 757 | 770 | ||
| 758 | **Example** | 771 | **Example** |
| @@ -778,9 +791,9 @@ let callback: Callback<emitter.GenericEventData<Sample>> = (eventData: emitter.G | |||
| 778 | if (eventData?.data instanceof Sample) { | 791 | if (eventData?.data instanceof Sample) { |
| 779 | eventData?.data?.printCount(); | 792 | eventData?.data?.printCount(); |
| 780 | } | 793 | } |
| 781 | -} | 794 | +}; |
| 782 | 795 | ||
| 783 | -emitter1.on("eventId", callback); | 796 | +emitter1.on('eventId', callback); |
| 784 | ``` | 797 | ``` |
| 785 | 798 | ||
| 786 | ### once<sup>22+</sup> | 799 | ### once<sup>22+</sup> |
| @@ -797,7 +810,7 @@ Subscribes to an event specified by the Emitter instance in one-shot manner and | |||
| 797 | 810 | ||
| 798 | | Name | Type | Mandatory| Description | | 811 | | Name | Type | Mandatory| Description | |
| 799 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 812 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 800 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 813 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 801 | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to be invoked when the event is received.| | 814 | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to be invoked when the event is received.| |
| 802 | 815 | ||
| 803 | **Example** | 816 | **Example** |
| @@ -809,9 +822,9 @@ let emitter1: emitter.Emitter = new emitter.Emitter(); | |||
| 809 | 822 | ||
| 810 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 823 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 811 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 824 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 812 | -} | 825 | +}; |
| 813 | 826 | ||
| 814 | -emitter1.once("eventId", callback); | 827 | +emitter1.once('eventId', callback); |
| 815 | ``` | 828 | ``` |
| 816 | 829 | ||
| 817 | ### once<sup>22+</sup> | 830 | ### once<sup>22+</sup> |
| @@ -828,7 +841,7 @@ Subscribes to an event specified by the Emitter instance in one-shot manner and | |||
| 828 | 841 | ||
| 829 | | Name | Type | Mandatory| Description | | 842 | | Name | Type | Mandatory| Description | |
| 830 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 843 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 831 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 844 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 832 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | Yes | Callback to be invoked when the event is received.| | 845 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | Yes | Callback to be invoked when the event is received.| |
| 833 | 846 | ||
| 834 | **Example** | 847 | **Example** |
| @@ -854,9 +867,9 @@ let callback: Callback<emitter.GenericEventData<Sample>> = (eventData: emitter.G | |||
| 854 | if (eventData?.data instanceof Sample) { | 867 | if (eventData?.data instanceof Sample) { |
| 855 | eventData?.data?.printCount(); | 868 | eventData?.data?.printCount(); |
| 856 | } | 869 | } |
| 857 | -} | 870 | +}; |
| 858 | 871 | ||
| 859 | -emitter1.once("eventId", callback); | 872 | +emitter1.once('eventId', callback); |
| 860 | ``` | 873 | ``` |
| 861 | 874 | ||
| 862 | ### off<sup>22+</sup> | 875 | ### off<sup>22+</sup> |
| @@ -875,14 +888,14 @@ After this API is used to unsubscribe from an event, the event that has been pub | |||
| 875 | 888 | ||
| 876 | | Name | Type | Mandatory| Description | | 889 | | Name | Type | Mandatory| Description | |
| 877 | | ------- | ------ | ---- | -------- | | 890 | | ------- | ------ | ---- | -------- | |
| 878 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty.| | 891 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated.| |
| 879 | 892 | ||
| 880 | **Example** | 893 | **Example** |
| 881 | 894 | ||
| 882 | ```ts | 895 | ```ts |
| 883 | let emitter1: emitter.Emitter = new emitter.Emitter(); | 896 | let emitter1: emitter.Emitter = new emitter.Emitter(); |
| 884 | 897 | ||
| 885 | -emitter1.off("eventId"); | 898 | +emitter1.off('eventId'); |
| 886 | ``` | 899 | ``` |
| 887 | 900 | ||
| 888 | ### off<sup>22+</sup> | 901 | ### off<sup>22+</sup> |
| @@ -901,7 +914,7 @@ After this API is used to unsubscribe from an event, the event that has been pub | |||
| 901 | 914 | ||
| 902 | | Name | Type | Mandatory| Description | | 915 | | Name | Type | Mandatory| Description | |
| 903 | | -------- | ----------------------------------- | ---- | -------------------------- | | 916 | | -------- | ----------------------------------- | ---- | -------------------------- | |
| 904 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 917 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 905 | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to unregister.| | 918 | | callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to unregister.| |
| 906 | 919 | ||
| 907 | **Example** | 920 | **Example** |
| @@ -913,9 +926,9 @@ let emitter1: emitter.Emitter = new emitter.Emitter(); | |||
| 913 | 926 | ||
| 914 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 927 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 915 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 928 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 916 | -} | 929 | +}; |
| 917 | 930 | ||
| 918 | -emitter1.off("eventId", callback); | 931 | +emitter1.off('eventId', callback); |
| 919 | ``` | 932 | ``` |
| 920 | 933 | ||
| 921 | ### off<sup>22+</sup> | 934 | ### off<sup>22+</sup> |
| @@ -934,7 +947,7 @@ After this API is used to unsubscribe from an event, the event that has been pub | |||
| 934 | 947 | ||
| 935 | | Name | Type | Mandatory| Description | | 948 | | Name | Type | Mandatory| Description | |
| 936 | | -------- | ----------------------------------- | ---- | -------------------------- | | 949 | | -------- | ----------------------------------- | ---- | -------------------------- | |
| 937 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 950 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 938 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | Yes | Callback to unregister.| | 951 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | Yes | Callback to unregister.| |
| 939 | 952 | ||
| 940 | **Example** | 953 | **Example** |
| @@ -960,9 +973,9 @@ let callback: Callback<emitter.GenericEventData<Sample>> = (eventData: emitter.G | |||
| 960 | if (eventData?.data instanceof Sample) { | 973 | if (eventData?.data instanceof Sample) { |
| 961 | eventData?.data?.printCount(); | 974 | eventData?.data?.printCount(); |
| 962 | } | 975 | } |
| 963 | -} | 976 | +}; |
| 964 | 977 | ||
| 965 | -emitter1.off("eventId", callback); | 978 | +emitter1.off('eventId', callback); |
| 966 | ``` | 979 | ``` |
| 967 | 980 | ||
| 968 | ### emit<sup>22+</sup> | 981 | ### emit<sup>22+</sup> |
| @@ -983,7 +996,7 @@ After an event is published using this API, the event may not be executed immedi | |||
| 983 | 996 | ||
| 984 | | Name | Type | Mandatory| Description | | 997 | | Name | Type | Mandatory| Description | |
| 985 | | ------- | ----------------------- | ---- | ---------------- | | 998 | | ------- | ----------------------- | ---- | ---------------- | |
| 986 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 999 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 987 | | data | [EventData](#eventdata) | No | Data carried by the event. This parameter is left empty by default.| | 1000 | | data | [EventData](#eventdata) | No | Data carried by the event. This parameter is left empty by default.| |
| 988 | 1001 | ||
| 989 | **Example** | 1002 | **Example** |
| @@ -992,12 +1005,12 @@ After an event is published using this API, the event may not be executed immedi | |||
| 992 | let emitter1: emitter.Emitter = new emitter.Emitter(); | 1005 | let emitter1: emitter.Emitter = new emitter.Emitter(); |
| 993 | let eventData: emitter.EventData = { | 1006 | let eventData: emitter.EventData = { |
| 994 | data: { | 1007 | data: { |
| 995 | - "content": "content", | 1008 | + "content": "content", |
| 996 | - "id": 1, | 1009 | + "id": 1, |
| 997 | } | 1010 | } |
| 998 | }; | 1011 | }; |
| 999 | 1012 | ||
| 1000 | -emitter1.emit("eventId", eventData); | 1013 | +emitter1.emit('eventId', eventData); |
| 1001 | ``` | 1014 | ``` |
| 1002 | 1015 | ||
| 1003 | ### emit<sup>22+</sup> | 1016 | ### emit<sup>22+</sup> |
| @@ -1018,7 +1031,7 @@ After an event is published using this API, the event may not be executed immedi | |||
| 1018 | 1031 | ||
| 1019 | | Name | Type | Mandatory| Description | | 1032 | | Name | Type | Mandatory| Description | |
| 1020 | | ------- | ----------------------- | ---- | ---------------- | | 1033 | | ------- | ----------------------- | ---- | ---------------- | |
| 1021 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty.| | 1034 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated.| |
| 1022 | | data | [GenericEventData<T\>](#genericeventdatat12) | No | Data carried by the event. This parameter is left empty by default.| | 1035 | | data | [GenericEventData<T\>](#genericeventdatat12) | No | Data carried by the event. This parameter is left empty by default.| |
| 1023 | 1036 | ||
| 1024 | **Example** | 1037 | **Example** |
| @@ -1041,14 +1054,14 @@ let eventData: emitter.GenericEventData<Sample> = { | |||
| 1041 | data: new Sample() | 1054 | data: new Sample() |
| 1042 | }; | 1055 | }; |
| 1043 | 1056 | ||
| 1044 | -emitter1.emit("eventId", eventData); | 1057 | +emitter1.emit('eventId', eventData); |
| 1045 | ``` | 1058 | ``` |
| 1046 | 1059 | ||
| 1047 | ### emit<sup>22+</sup> | 1060 | ### emit<sup>22+</sup> |
| 1048 | 1061 | ||
| 1049 | emit(eventId: string, options: Options, data?: EventData): void | 1062 | emit(eventId: string, options: Options, data?: EventData): void |
| 1050 | 1063 | ||
| 1051 | -Emits a specified event to the Emitter class instance. | 1064 | +Emits an event of a specified priority to the Emitter instance. |
| 1052 | 1065 | ||
| 1053 | This API can be used to emit data objects across threads. The data objects must meet the specifications specified in [Overview of Inter-Thread Communication Objects](../../arkts-utils/serializable-overview.md). Currently, complex data decorated by decorators such as [@State](../../ui/state-management/arkts-state.md) and [@Observed](../../ui/state-management/arkts-observed-and-objectlink.md) is not supported. | 1066 | This API can be used to emit data objects across threads. The data objects must meet the specifications specified in [Overview of Inter-Thread Communication Objects](../../arkts-utils/serializable-overview.md). Currently, complex data decorated by decorators such as [@State](../../ui/state-management/arkts-state.md) and [@Observed](../../ui/state-management/arkts-observed-and-objectlink.md) is not supported. |
| 1054 | 1067 | ||
| @@ -1062,7 +1075,7 @@ After an event is published using this API, the event may not be executed immedi | |||
| 1062 | 1075 | ||
| 1063 | | Name | Type | Mandatory| Description | | 1076 | | Name | Type | Mandatory| Description | |
| 1064 | | ------- | ----------------------- | ---- | ---------------- | | 1077 | | ------- | ----------------------- | ---- | ---------------- | |
| 1065 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 1078 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 1066 | | options | [Options](#options11) | Yes | Event emit priority. | | 1079 | | options | [Options](#options11) | Yes | Event emit priority. | |
| 1067 | | data | [EventData](#eventdata) | No | Data carried by the event. This parameter is left empty by default.| | 1080 | | data | [EventData](#eventdata) | No | Data carried by the event. This parameter is left empty by default.| |
| 1068 | 1081 | ||
| @@ -1076,12 +1089,12 @@ let options: emitter.Options = { | |||
| 1076 | }; | 1089 | }; |
| 1077 | let eventData: emitter.EventData = { | 1090 | let eventData: emitter.EventData = { |
| 1078 | data: { | 1091 | data: { |
| 1079 | - "content": "content", | 1092 | + "content": "content", |
| 1080 | - "id": 1, | 1093 | + "id": 1, |
| 1081 | } | 1094 | } |
| 1082 | }; | 1095 | }; |
| 1083 | 1096 | ||
| 1084 | -emitter1.emit("eventId", options, eventData); | 1097 | +emitter1.emit('eventId', options, eventData); |
| 1085 | ``` | 1098 | ``` |
| 1086 | 1099 | ||
| 1087 | ### emit<sup>22+</sup> | 1100 | ### emit<sup>22+</sup> |
| @@ -1102,7 +1115,7 @@ After an event is published using this API, the event may not be executed immedi | |||
| 1102 | 1115 | ||
| 1103 | | Name | Type | Mandatory| Description | | 1116 | | Name | Type | Mandatory| Description | |
| 1104 | | ------- | ----------------------- | ---- | ---------------- | | 1117 | | ------- | ----------------------- | ---- | ---------------- | |
| 1105 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty. | | 1118 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated. | |
| 1106 | | options | [Options](#options11) | Yes | Event emit priority. | | 1119 | | options | [Options](#options11) | Yes | Event emit priority. | |
| 1107 | | data | [GenericEventData<T\>](#genericeventdatat12) | No | Data carried by the event. This parameter is left empty by default.| | 1120 | | data | [GenericEventData<T\>](#genericeventdatat12) | No | Data carried by the event. This parameter is left empty by default.| |
| 1108 | 1121 | ||
| @@ -1129,7 +1142,7 @@ let eventData: emitter.GenericEventData<Sample> = { | |||
| 1129 | data: new Sample() | 1142 | data: new Sample() |
| 1130 | }; | 1143 | }; |
| 1131 | 1144 | ||
| 1132 | -emitter1.emit("eventId", options, eventData); | 1145 | +emitter1.emit('eventId', options, eventData); |
| 1133 | ``` | 1146 | ``` |
| 1134 | 1147 | ||
| 1135 | ### getListenerCount<sup>22+</sup> | 1148 | ### getListenerCount<sup>22+</sup> |
| @@ -1146,9 +1159,9 @@ Obtains the number of subscriptions to a specified event of the Emitter instance | |||
| 1146 | 1159 | ||
| 1147 | | Name | Type | Mandatory| Description | | 1160 | | Name | Type | Mandatory| Description | |
| 1148 | | ------- | -------------- | ---- | -------- | | 1161 | | ------- | -------------- | ---- | -------- | |
| 1149 | -| eventId | string | Yes | Event ID, which is a custom string with a maximum of 10240 bytes. The value cannot be empty.| | 1162 | +| eventId | string | Yes | Event ID,<br>which cannot be empty or exceed 10,240 bytes. Excess content will be truncated.| |
| 1150 | 1163 | ||
| 1151 | -**Returns** | 1164 | +**Return value** |
| 1152 | 1165 | ||
| 1153 | | Type | Description | | 1166 | | Type | Description | |
| 1154 | | ----- | ----- | | 1167 | | ----- | ----- | |
| @@ -1159,5 +1172,5 @@ Obtains the number of subscriptions to a specified event of the Emitter instance | |||
| 1159 | 1172 | ||
| 1160 | ```ts | 1173 | ```ts |
| 1161 | let emitter1: emitter.Emitter = new emitter.Emitter(); | 1174 | let emitter1: emitter.Emitter = new emitter.Emitter(); |
| 1162 | -let count = emitter1.getListenerCount("eventId"); | 1175 | +let count: number = emitter1.getListenerCount('eventId'); |
| 1163 | ``` | 1176 | ``` |
Men/application-dev/reference/apis-basic-services-kit/js-apis-inner-commonEvent-commonEventData.md+4-4
| @@ -6,7 +6,7 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -Describes the data of a common event. | 9 | +Describes the data of a common event. The **CommonEventData** module is used to carry the common event data received by subscribers in common event subscription scenarios. The data includes the event name, publisher bundle name, code, data, and additional parameters. This module is applicable to scenarios where apps subscribe to and process common events and parse the data carried in the events. |
| 10 | 10 | ||
| 11 | > **NOTE** | 11 | > **NOTE** |
| 12 | > | 12 | > |
| @@ -21,7 +21,7 @@ Describes the data of a common event. | |||
| 21 | | Name | Type | Read Only| Optional| Description | | 21 | | Name | Type | Read Only| Optional| Description | |
| 22 | | ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- | | 22 | | ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- | |
| 23 | | event | string | No | No | Name of the common event that is being received. | | 23 | | event | string | No | No | Name of the common event that is being received. | |
| 24 | -| bundleName | string | No | Yes | Bundle name. The default value is an empty string. | | 24 | +| bundleName | string | No | Yes | Bundle name of the common event publisher. The default value is an empty string. | |
| 25 | -| code | number | No | Yes | Common event data received by the subscriber. The value of this field is the same as that of the **code** field in [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) when the publisher uses [commonEventManager.publish](./js-apis-commonEventManager.md#commoneventmanagerpublish-1) to publish a common event. The default value is **0**. | | 25 | +| code | number | No | Yes | Common event data received by the subscriber. The value of this field is the same as that of the **code** field in [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) when the publisher uses [commonEventManager.publish](./js-apis-commonEventManager.md#commoneventmanagerpublish-1) to publish a common event. The value ranges from –2147483648 to 2147483647. The default value is **0**. | |
| 26 | -| data | string | No | Yes | Common event data received by the subscriber. The value of this field is the same as that of the **data** field in [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) when the publisher uses [commonEventManager.publish](./js-apis-commonEventManager.md#commoneventmanagerpublish-1) to publish a common event.| | 26 | +| data | string | No | Yes | Common event data received by the subscriber. The data size cannot exceed 64 KB. The value of this field is the same as that of the **data** field in [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) when the publisher uses [commonEventManager.publish](./js-apis-commonEventManager.md#commoneventmanagerpublish-1) to publish a common event.| |
| 27 | | parameters | {[key: string]: any} | No | Yes | Additional information about the common event received by the subscriber. The value of this field is the same as that of the **parameters** field in [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) when the publisher uses [commonEventManager.publish](./js-apis-commonEventManager.md#commoneventmanagerpublish-1) to publish a common event. | | 27 | | parameters | {[key: string]: any} | No | Yes | Additional information about the common event received by the subscriber. The value of this field is the same as that of the **parameters** field in [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) when the publisher uses [commonEventManager.publish](./js-apis-commonEventManager.md#commoneventmanagerpublish-1) to publish a common event. | |
| @@ -6,13 +6,13 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -The **CommonEventPublishData** module provides APIs for defining common event content and attributes. | 9 | +This module encapsulates the data and attributes carried when a common event is published, including the event data (code/data), subscriber permissions, subscriber bundle name, whether the event is ordered or sticky, and additional parameters. It allows the publisher to precisely control the common event recipients, event delivery sequence, and sticky feature. This module is applicable to scenarios where the recipients need to be specified, custom event data needs to be transferred, and ordered/sticky common events need to be implemented. |
| 10 | 10 | ||
| 11 | > **NOTE** | 11 | > **NOTE** |
| 12 | > | 12 | > |
| 13 | > 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. | 13 | > 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. |
| 14 | > | 14 | > |
| 15 | -> If there is no restriction, any application can subscribe to common events and read related information. In this case, sensitive information should not be carried in common events. The **subscriberPermissions** and **bundleName** parameters of this module can be used to restrict the receiving scope of common events. | 15 | +> If there is no restriction, any app can subscribe to common events and read the information carried by the event. In this case, sensitive information should not be carried in common events. The **subscriberPermissions** and **bundleName** parameters of this module can be used to restrict the receiving scope of common events. |
| 16 | 16 | ||
| 17 | ## Properties | 17 | ## Properties |
| 18 | 18 | ||
| @@ -20,10 +20,10 @@ The **CommonEventPublishData** module provides APIs for defining common event co | |||
| 20 | 20 | ||
| 21 | | Name | Type | Read Only| Optional| Description | | 21 | | Name | Type | Read Only| Optional| Description | |
| 22 | | --------------------- | -------------------- | ---- | ---- | ---------------------------- | | 22 | | --------------------- | -------------------- | ---- | ---- | ---------------------------- | |
| 23 | -| bundleName | string | No | Yes | Bundle name of the subscriber that can receive the common event.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| | 23 | +| bundleName | string | No | Yes | Bundle name of the subscriber, which is used to specify the subscriber to whom the common event is published.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| |
| 24 | | code | number | No | Yes | Common event data transferred by the publisher. The default value is **0**.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | | 24 | | code | number | No | Yes | Common event data transferred by the publisher. The default value is **0**.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | |
| 25 | | data | string | No | Yes | Common event data transferred by the publisher. The data size cannot exceed 64 KB.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| | 25 | | data | string | No | Yes | Common event data transferred by the publisher. The data size cannot exceed 64 KB.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| |
| 26 | -| subscriberPermissions | Array\<string> | No | Yes | Permissions required for subscribers to receive the common event.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | | 26 | +| subscriberPermissions | Array\<string> | No | Yes | Subscriber permissions. Only subscribers with the specified permissions can receive the common event.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | |
| 27 | | isOrdered | boolean | No | Yes | Whether the common event is an ordered one. The default value is **false**.<br> - **true**: This event is an ordered common event. Based on the priority set by the subscriber, the common event is preferentially sent to the subscriber with a higher priority. After the subscriber successfully receives the event, the public event is sent to the subscriber with a lower priority. Subscribers with the same priority receive common events in a random order.<br> - **false**: This event is an unordered common event. Whether subscribers receive the event is not considered, and the common event which subscribers receive may not comply with the subscription sequence. | | 27 | | isOrdered | boolean | No | Yes | Whether the common event is an ordered one. The default value is **false**.<br> - **true**: This event is an ordered common event. Based on the priority set by the subscriber, the common event is preferentially sent to the subscriber with a higher priority. After the subscriber successfully receives the event, the public event is sent to the subscriber with a lower priority. Subscribers with the same priority receive common events in a random order.<br> - **false**: This event is an unordered common event. Whether subscribers receive the event is not considered, and the common event which subscribers receive may not comply with the subscription sequence. | |
| 28 | | isSticky | boolean | No | Yes | Whether the common event is a sticky one. The default value is **false**.<br> - **true**: This event is a sticky common event, which allows subscribers to receive common events that have been sent before subscription.<br> - **false**: This event is not a sticky common event, which allows subscribers to receive common events sent after subscription.<br>Only system applications and system services are allowed to send sticky events.<br>**Required Permissions**: [ohos.permission.COMMONEVENT_STICKY](../../security/AccessToken/permissions-for-all.md#ohospermissioncommonevent_sticky)| | 28 | | isSticky | boolean | No | Yes | Whether the common event is a sticky one. The default value is **false**.<br> - **true**: This event is a sticky common event, which allows subscribers to receive common events that have been sent before subscription.<br> - **false**: This event is not a sticky common event, which allows subscribers to receive common events sent after subscription.<br>Only system applications and system services are allowed to send sticky events.<br>**Required Permissions**: [ohos.permission.COMMONEVENT_STICKY](../../security/AccessToken/permissions-for-all.md#ohospermissioncommonevent_sticky)| |
| 29 | -| parameters | {[key: string]: any} | No | Yes | Additional information about the common event transferred by the publisher.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | | 29 | +| parameters | {[key: string]: any} | No | Yes | Additional information about the common event transferred by the publisher. Custom parameters are configured in a key-value pair format.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | |
| @@ -6,25 +6,25 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -The **CommonEventSubscribeInfo** module provides APIs for providing subscriber information. | 9 | +This module provides APIs for providing subscriber information. It allows you to configure parameters such as the subscribed common event type, publisher permission, publisher device ID, user ID, and subscription priority. This module is applicable to scenarios where an app needs to subscribe to system common events or custom common events and requires refined control over event sources. |
| 10 | 10 | ||
| 11 | > **NOTE** | 11 | > **NOTE** |
| 12 | > | 12 | > |
| 13 | > 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. | 13 | > 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. |
| 14 | > | 14 | > |
| 15 | -> After users subscribing to custom common events, any application can send potential malicious common events to subscribers. Use the **publisherPermission** and **publisherBundleName** parameters of this module to restrict the publishing scope of common events. | 15 | +> After users subscribing to custom common events, any application can send potential malicious common events to subscribers. The **publisherPermission** and **publisherBundleName** parameters of this module can be used to restrict the publisher scope of common events. |
| 16 | 16 | ||
| 17 | ## Attributes | 17 | ## Attributes |
| 18 | 18 | ||
| 19 | -**Atomic service API**: This API can be used in atomic services since API version 11. | 19 | +**Atomic service API:** This API can be used in atomic services since API version 11. |
| 20 | 20 | ||
| 21 | -**System capability**: SystemCapability.Notification.CommonEvent | 21 | +**System capability:** SystemCapability.Notification.CommonEvent |
| 22 | 22 | ||
| 23 | | Name | Type | Read Only| Optional| Description | | 23 | | Name | Type | Read Only| Optional| Description | |
| 24 | | ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | | 24 | | ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | |
| 25 | | events | Array\<string> | No | No | Common events to subscribe to. | | 25 | | events | Array\<string> | No | No | Common events to subscribe to. | |
| 26 | -| publisherPermission | string | No | Yes | Permission of the publisher. The subscriber can receive only the events from the publisher with this permission. | | 26 | +| publisherPermission | string | No | Yes | Permission of the publisher. The value is an array of permission names defined by the system. The subscriber can receive only the events from the publisher with this permission. If this parameter is not set, the subscriber can receive events from all publishers. | |
| 27 | -| publisherDeviceId | string | No | Yes | Device ID. Use [@ohos.deviceInfo](js-apis-device-info.md) to obtain the UDID as the device ID of the subscriber. Not supported currently. | | 27 | +| publisherDeviceId | string | No | Yes | Device ID, which is used to restrict the subscriber to receive only public events published by the specified device. Use [@ohos.deviceInfo](js-apis-device-info.md) to obtain the UDID as the device ID of the publisher. Not supported currently. | |
| 28 | -| userId | number | No | Yes | User ID. If this parameter is not specified, the default value, which is the ID of the current user, will be used. The value must be an existing user ID in the system. Use [getOsAccountLocalId](./js-apis-osAccount.md#getosaccountlocalid9) to obtain the system account ID and use it as the user ID of the subscriber.| | 28 | +| userId | number | No | Yes | User ID, which is used to restrict the subscriber to receive only public events related to the specified user ID. If this parameter is not specified, the default value, which is the ID of the current user, will be used. The value must be an existing user ID in the system. Use [getOsAccountLocalId](./js-apis-osAccount.md#getosaccountlocalid9) to obtain the system user ID and use it as the user ID of the publisher.| |
| 29 | -| priority | number | No | Yes | Subscriber priority. The value ranges from –100 to +1000. If the value exceeds the upper or lower limit, the upper or lower limit is used. | | 29 | +| priority | number | No | Yes | Subscriber priority. Subscribers with higher priorities receive ordered public events first. The value ranges from –100 to 1000. If the value exceeds the upper or lower limit, the upper or lower limit is used. The default value is **0**. | |
| 30 | -| publisherBundleName<sup>11+</sup> | string | No | Yes | Bundle name of the publisher to subscribe to. | | 30 | +| publisherBundleName<sup>11+</sup> | string | No | Yes | Bundle name of the publisher to be subscribed to. This parameter is used to restrict the subscriber to receive only public events published by the publisher with the specified bundle name. If this parameter is not set, the subscriber can receive all public events published by the app. | |
| @@ -12,7 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | ## CommonEventSubscriber | 13 | ## CommonEventSubscriber |
| 14 | 14 | ||
| 15 | -The **CommonEventSubscriber** module provides APIs for describing the common event subscriber. | 15 | +The **CommonEventSubscriber** module provides APIs for describing the common event subscriber. The **CommonEventSubscriber** module provides the capabilities for processing ordered common events, including obtaining and setting the code and data transferred by events, checking whether the current common event is an ordered or sticky event, terminating an ordered common event or clearing the termination status, ending the processing of the current ordered common event, and obtaining subscription information of a subscriber. This module is applicable to data processing and process control of the received common event by the subscriber. |
| 16 | 16 | ||
| 17 | **Atomic service API**: This API can be used in atomic services since API version 11. | 17 | **Atomic service API**: This API can be used in atomic services since API version 11. |
| 18 | 18 | ||
| @@ -20,7 +20,7 @@ The **CommonEventSubscriber** module provides APIs for describing the common eve | |||
| 20 | 20 | ||
| 21 | ### How to Use | 21 | ### How to Use |
| 22 | 22 | ||
| 23 | -Before using the **CommonEventSubscriber** module, you must obtain a **subscriber** object by calling **commonEventManager.createSubscriber**. | 23 | +Before using the **CommonEventSubscriber** module, you must obtain a **subscriber** object by calling [commonEventManager.createSubscriberSync](js-apis-commonEventManager.md#commoneventmanagercreatesubscribersync10). |
| 24 | 24 | ||
| 25 | <!--code_no_check--> | 25 | <!--code_no_check--> |
| 26 | ```ts | 26 | ```ts |
| @@ -51,7 +51,7 @@ Obtains the result code (number type) of an ordered common event. This API uses | |||
| 51 | 51 | ||
| 52 | | Name | Type | Mandatory| Description | | 52 | | Name | Type | Mandatory| Description | |
| 53 | | -------- | ---------------------- | ---- | ------------------ | | 53 | | -------- | ---------------------- | ---- | ------------------ | |
| 54 | -| callback | AsyncCallback\<number\> | Yes | Callback used to return the result.| | 54 | +| callback | AsyncCallback\<number\> | Yes | Callback used to return the result. If the result code (number type) of an ordered common event is successfully obtained, **err** is **undefined**, and **data** is the code obtained; otherwise, **err** is an error object.| |
| 55 | 55 | ||
| 56 | **Error codes** | 56 | **Error codes** |
| 57 | 57 | ||
| @@ -59,7 +59,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 59 | 59 | ||
| 60 | | ID| Error Message | | 60 | | ID| Error Message | |
| 61 | | -------- | ----------------------------------- | | 61 | | -------- | ----------------------------------- | |
| 62 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 62 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 63 | 63 | ||
| 64 | **Example** | 64 | **Example** |
| 65 | 65 | ||
| @@ -68,7 +68,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 68 | ```ts | 68 | ```ts |
| 69 | subscriber.getCode((err: BusinessError, code: number) => { | 69 | subscriber.getCode((err: BusinessError, code: number) => { |
| 70 | if (err) { | 70 | if (err) { |
| 71 | - console.error(`Failed to get code. Code is ${err.code}, message is ${err.message}`); | 71 | + console.error(`Failed to get code. Code: ${err.code}, message: ${err.message}`); |
| 72 | return; | 72 | return; |
| 73 | } | 73 | } |
| 74 | console.info(`Succeeded in getting code, code is ${JSON.stringify(code)}`); | 74 | console.info(`Succeeded in getting code, code is ${JSON.stringify(code)}`); |
| @@ -107,7 +107,7 @@ subscriber.getCode().then((code: number) => { | |||
| 107 | 107 | ||
| 108 | getCodeSync(): number | 108 | getCodeSync(): number |
| 109 | 109 | ||
| 110 | -Obtains the result code (number type) of an ordered common event. | 110 | +Obtains the result code (number type) of an ordered common event synchronously. |
| 111 | 111 | ||
| 112 | **Atomic service API**: This API can be used in atomic services since API version 11. | 112 | **Atomic service API**: This API can be used in atomic services since API version 11. |
| 113 | 113 | ||
| @@ -151,7 +151,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 151 | 151 | ||
| 152 | | ID| Error Message | | 152 | | ID| Error Message | |
| 153 | | -------- | ----------------------------------- | | 153 | | -------- | ----------------------------------- | |
| 154 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 154 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 155 | 155 | ||
| 156 | **Example** | 156 | **Example** |
| 157 | 157 | ||
| @@ -195,7 +195,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 195 | 195 | ||
| 196 | | ID| Error Message | | 196 | | ID| Error Message | |
| 197 | | -------- | ----------------------------------- | | 197 | | -------- | ----------------------------------- | |
| 198 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 198 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 199 | 199 | ||
| 200 | **Example** | 200 | **Example** |
| 201 | 201 | ||
| @@ -231,7 +231,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 231 | 231 | ||
| 232 | | ID| Error Message | | 232 | | ID| Error Message | |
| 233 | | -------- | ----------------------------------- | | 233 | | -------- | ----------------------------------- | |
| 234 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 234 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 235 | 235 | ||
| 236 | **Example** | 236 | **Example** |
| 237 | 237 | ||
| @@ -260,7 +260,7 @@ Obtains the result data (string type) of an ordered common event. This API uses | |||
| 260 | 260 | ||
| 261 | | Name | Type | Mandatory| Description | | 261 | | Name | Type | Mandatory| Description | |
| 262 | | -------- | ---------------------- | ---- | -------------------- | | 262 | | -------- | ---------------------- | ---- | -------------------- | |
| 263 | -| callback | AsyncCallback\<string> | Yes | Callback used to return the result.| | 263 | +| callback | AsyncCallback\<string> | Yes | Callback used to return the result. If the result data (string type) of an ordered common event is successfully obtained, **err** is **undefined**, and **data** is the data obtained; otherwise, **err** is an error object.| |
| 264 | 264 | ||
| 265 | **Error codes** | 265 | **Error codes** |
| 266 | 266 | ||
| @@ -268,7 +268,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 268 | 268 | ||
| 269 | | ID| Error Message | | 269 | | ID| Error Message | |
| 270 | | -------- | ----------------------------------- | | 270 | | -------- | ----------------------------------- | |
| 271 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 271 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 272 | 272 | ||
| 273 | **Example** | 273 | **Example** |
| 274 | 274 | ||
| @@ -352,7 +352,7 @@ Sets the result data (string type) of an ordered common event. This API uses an | |||
| 352 | 352 | ||
| 353 | | Name | Type | Mandatory| Description | | 353 | | Name | Type | Mandatory| Description | |
| 354 | | -------- | -------------------- | ---- | -------------------- | | 354 | | -------- | -------------------- | ---- | -------------------- | |
| 355 | -| data | string | Yes | Result data of an ordered common event. | | 355 | +| data | string | Yes | Result data (string type) of an ordered common event. The value is a string containing a maximum of 65,536 characters. If the length exceeds the limit, the API setting becomes invalid. | |
| 356 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| | 356 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| |
| 357 | 357 | ||
| 358 | **Error codes** | 358 | **Error codes** |
| @@ -361,7 +361,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 361 | 361 | ||
| 362 | | ID| Error Message | | 362 | | ID| Error Message | |
| 363 | | -------- | ----------------------------------- | | 363 | | -------- | ----------------------------------- | |
| 364 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 364 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 365 | 365 | ||
| 366 | **Example** | 366 | **Example** |
| 367 | 367 | ||
| @@ -405,7 +405,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 405 | 405 | ||
| 406 | | ID| Error Message | | 406 | | ID| Error Message | |
| 407 | | -------- | ----------------------------------- | | 407 | | -------- | ----------------------------------- | |
| 408 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 408 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 409 | 409 | ||
| 410 | **Example** | 410 | **Example** |
| 411 | 411 | ||
| @@ -433,7 +433,7 @@ Sets the result data (string type) of an ordered common event. | |||
| 433 | 433 | ||
| 434 | | Name| Type | Mandatory| Description | | 434 | | Name| Type | Mandatory| Description | |
| 435 | | ------ | ------ | ---- | -------------------- | | 435 | | ------ | ------ | ---- | -------------------- | |
| 436 | -| data | string | Yes | Result data of an ordered common event.| | 436 | +| data | string | Yes | Result data (string type) of an ordered common event. The value is a string containing a maximum of 65,536 characters. If the length exceeds the limit, the API setting becomes invalid.| |
| 437 | 437 | ||
| 438 | **Error codes** | 438 | **Error codes** |
| 439 | 439 | ||
| @@ -441,7 +441,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 441 | 441 | ||
| 442 | | ID| Error Message | | 442 | | ID| Error Message | |
| 443 | | -------- | ----------------------------------- | | 443 | | -------- | ----------------------------------- | |
| 444 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 444 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 445 | 445 | ||
| 446 | **Example** | 446 | **Example** |
| 447 | 447 | ||
| @@ -458,7 +458,7 @@ try { | |||
| 458 | 458 | ||
| 459 | ### setCodeAndData | 459 | ### setCodeAndData |
| 460 | 460 | ||
| 461 | -setCodeAndData(code: number, data: string, callback:AsyncCallback\<void>): void | 461 | +setCodeAndData(code: number, data: string, callback: AsyncCallback\<void\>): void |
| 462 | 462 | ||
| 463 | Sets the result code and data of an ordered common event. This API uses an asynchronous callback to return the result. | 463 | Sets the result code and data of an ordered common event. This API uses an asynchronous callback to return the result. |
| 464 | 464 | ||
| @@ -471,7 +471,7 @@ Sets the result code and data of an ordered common event. This API uses an async | |||
| 471 | | Name | Type | Mandatory| Description | | 471 | | Name | Type | Mandatory| Description | |
| 472 | | -------- | -------------------- | ---- | ---------------------- | | 472 | | -------- | -------------------- | ---- | ---------------------- | |
| 473 | | code | number | Yes | Result code of an ordered common event. | | 473 | | code | number | Yes | Result code of an ordered common event. | |
| 474 | -| data | string | Yes | Result data of an ordered common event. | | 474 | +| data | string | Yes | Result data (string type) of an ordered common event. The value is a string containing a maximum of 65,536 characters. If the length exceeds the limit, the API setting becomes invalid. | |
| 475 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| | 475 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| |
| 476 | 476 | ||
| 477 | **Error codes** | 477 | **Error codes** |
| @@ -480,7 +480,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 480 | 480 | ||
| 481 | | ID| Error Message | | 481 | | ID| Error Message | |
| 482 | | -------- | ----------------------------------- | | 482 | | -------- | ----------------------------------- | |
| 483 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 483 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 484 | 484 | ||
| 485 | **Example** | 485 | **Example** |
| 486 | 486 | ||
| @@ -511,7 +511,7 @@ Sets the result code and data of an ordered common event. This API uses a promis | |||
| 511 | | Name| Type | Mandatory| Description | | 511 | | Name| Type | Mandatory| Description | |
| 512 | | ------ | ------ | ---- | -------------------- | | 512 | | ------ | ------ | ---- | -------------------- | |
| 513 | | code | number | Yes | Result code of an ordered common event.| | 513 | | code | number | Yes | Result code of an ordered common event.| |
| 514 | -| data | string | Yes | Result data of an ordered common event.| | 514 | +| data | string | Yes | Result data (string type) of an ordered common event. The value is a string containing a maximum of 65,536 characters. If the length exceeds the limit, the API setting becomes invalid.| |
| 515 | 515 | ||
| 516 | **Return value** | 516 | **Return value** |
| 517 | 517 | ||
| @@ -525,7 +525,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 525 | 525 | ||
| 526 | | ID| Error Message | | 526 | | ID| Error Message | |
| 527 | | -------- | ----------------------------------- | | 527 | | -------- | ----------------------------------- | |
| 528 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 528 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 529 | 529 | ||
| 530 | **Example** | 530 | **Example** |
| 531 | 531 | ||
| @@ -554,7 +554,7 @@ Sets the result code and data of an ordered common event. | |||
| 554 | | Name| Type | Mandatory| Description | | 554 | | Name| Type | Mandatory| Description | |
| 555 | | ------ | ------ | ---- | -------------------- | | 555 | | ------ | ------ | ---- | -------------------- | |
| 556 | | code | number | Yes | Result code of an ordered common event.| | 556 | | code | number | Yes | Result code of an ordered common event.| |
| 557 | -| data | string | Yes | Result data of an ordered common event.| | 557 | +| data | string | Yes | Result data (string type) of an ordered common event. The value is a string containing a maximum of 65,536 characters. If the length exceeds the limit, the API setting becomes invalid.| |
| 558 | 558 | ||
| 559 | **Error codes** | 559 | **Error codes** |
| 560 | 560 | ||
| @@ -562,7 +562,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 562 | 562 | ||
| 563 | | ID| Error Message | | 563 | | ID| Error Message | |
| 564 | | -------- | ----------------------------------- | | 564 | | -------- | ----------------------------------- | |
| 565 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 565 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 566 | 566 | ||
| 567 | **Example** | 567 | **Example** |
| 568 | 568 | ||
| @@ -590,7 +590,7 @@ Checks whether the current common event is an ordered common event. This API use | |||
| 590 | 590 | ||
| 591 | | Name | Type | Mandatory| Description | | 591 | | Name | Type | Mandatory| Description | |
| 592 | | -------- | ----------------------- | ---- | ---------------------------------- | | 592 | | -------- | ----------------------- | ---- | ---------------------------------- | |
| 593 | -| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. Returns **true** if the common event is an ordered one; returns **false** if the common event is an unordered one.| | 593 | +| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. If the query is successful, **err** is **undefined**. If **data** is **true**, the common event is ordered; if **data** is **false**, the common event is not ordered. Otherwise, **err** is an error object.| |
| 594 | 594 | ||
| 595 | **Error codes** | 595 | **Error codes** |
| 596 | 596 | ||
| @@ -598,16 +598,16 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 598 | 598 | ||
| 599 | | ID| Error Message | | 599 | | ID| Error Message | |
| 600 | | -------- | ----------------------------------- | | 600 | | -------- | ----------------------------------- | |
| 601 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 601 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 602 | 602 | ||
| 603 | **Example** | 603 | **Example** |
| 604 | 604 | ||
| 605 | <!--code_no_check--> | 605 | <!--code_no_check--> |
| 606 | 606 | ||
| 607 | ```ts | 607 | ```ts |
| 608 | -subscriber.isOrderedCommonEvent((err: BusinessError, isOrdered:boolean) => { | 608 | +subscriber.isOrderedCommonEvent((err: BusinessError, isOrdered: boolean) => { |
| 609 | if (err) { | 609 | if (err) { |
| 610 | - console.error(`isOrderedCommonEvent failed, code is ${err.code}, message is ${err.message}`); | 610 | + console.error(`Failed to check ordered common event. Code: ${err.code}, message: ${err.message}`); |
| 611 | return; | 611 | return; |
| 612 | } | 612 | } |
| 613 | console.info(`isOrderedCommonEvent ${JSON.stringify(isOrdered)}`); | 613 | console.info(`isOrderedCommonEvent ${JSON.stringify(isOrdered)}`); |
| @@ -633,7 +633,7 @@ Checks whether the current common event is an ordered common event. This API use | |||
| 633 | <!--code_no_check--> | 633 | <!--code_no_check--> |
| 634 | 634 | ||
| 635 | ```ts | 635 | ```ts |
| 636 | -subscriber.isOrderedCommonEvent().then((isOrdered:boolean) => { | 636 | +subscriber.isOrderedCommonEvent().then((isOrdered: boolean) => { |
| 637 | console.info(`isOrderedCommonEvent ${JSON.stringify(isOrdered)}`); | 637 | console.info(`isOrderedCommonEvent ${JSON.stringify(isOrdered)}`); |
| 638 | }).catch((err: BusinessError) => { | 638 | }).catch((err: BusinessError) => { |
| 639 | console.error(`isOrderedCommonEvent failed, code is ${err.code}, message is ${err.message}`); | 639 | console.error(`isOrderedCommonEvent failed, code is ${err.code}, message is ${err.message}`); |
| @@ -652,7 +652,7 @@ Checks whether the current common event is an ordered common event. | |||
| 652 | 652 | ||
| 653 | | Type | Description | | 653 | | Type | Description | |
| 654 | | ----------------- | -------------------------------- | | 654 | | ----------------- | -------------------------------- | |
| 655 | -| boolean |Returns **true** if the common event is an ordered one; returns **false** if the common event is an unordered one.| | 655 | +| boolean | Returns **true** if the common event is an ordered one; returns **false** if the common event is an unordered one.| |
| 656 | 656 | ||
| 657 | **Example** | 657 | **Example** |
| 658 | 658 | ||
| @@ -667,7 +667,7 @@ console.info(`isOrderedCommonEventSync ${JSON.stringify(isOrdered)}`); | |||
| 667 | 667 | ||
| 668 | isStickyCommonEvent(callback: AsyncCallback\<boolean>): void | 668 | isStickyCommonEvent(callback: AsyncCallback\<boolean>): void |
| 669 | 669 | ||
| 670 | -Checks whether a common event is a sticky one. This API uses an asynchronous callback to return the result. | 670 | +Checks whether the current common event is a sticky common event. This API uses an asynchronous callback to return the result. |
| 671 | 671 | ||
| 672 | **System capability**: SystemCapability.Notification.CommonEvent | 672 | **System capability**: SystemCapability.Notification.CommonEvent |
| 673 | 673 | ||
| @@ -675,7 +675,7 @@ Checks whether a common event is a sticky one. This API uses an asynchronous cal | |||
| 675 | 675 | ||
| 676 | | Name | Type | Mandatory| Description | | 676 | | Name | Type | Mandatory| Description | |
| 677 | | -------- | ----------------------- | ---- | ---------------------------------- | | 677 | | -------- | ----------------------- | ---- | ---------------------------------- | |
| 678 | -| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. Returns **true** if the common event is a sticky one; returns **false** otherwise.| | 678 | +| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. If the query is successful, **err** is **undefined**. If **data** is **true**, the common event is sticky; if **data** is **false**, the common event is not sticky. Otherwise, **err** is an error object.| |
| 679 | 679 | ||
| 680 | **Error codes** | 680 | **Error codes** |
| 681 | 681 | ||
| @@ -683,14 +683,14 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 683 | 683 | ||
| 684 | | ID| Error Message | | 684 | | ID| Error Message | |
| 685 | | -------- | ----------------------------------- | | 685 | | -------- | ----------------------------------- | |
| 686 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 686 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 687 | 687 | ||
| 688 | **Example** | 688 | **Example** |
| 689 | 689 | ||
| 690 | <!--code_no_check--> | 690 | <!--code_no_check--> |
| 691 | 691 | ||
| 692 | ```ts | 692 | ```ts |
| 693 | -subscriber.isStickyCommonEvent((err: BusinessError, isSticky:boolean) => { | 693 | +subscriber.isStickyCommonEvent((err: BusinessError, isSticky: boolean) => { |
| 694 | if (err) { | 694 | if (err) { |
| 695 | console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`); | 695 | console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`); |
| 696 | return; | 696 | return; |
| @@ -703,7 +703,7 @@ subscriber.isStickyCommonEvent((err: BusinessError, isSticky:boolean) => { | |||
| 703 | 703 | ||
| 704 | isStickyCommonEvent(): Promise\<boolean> | 704 | isStickyCommonEvent(): Promise\<boolean> |
| 705 | 705 | ||
| 706 | -Checks whether a common event is a sticky one. This API uses a promise to return the result. | 706 | +Checks whether the current common event is a sticky common event. This API uses a promise to return the result. |
| 707 | 707 | ||
| 708 | **System capability**: SystemCapability.Notification.CommonEvent | 708 | **System capability**: SystemCapability.Notification.CommonEvent |
| 709 | 709 | ||
| @@ -718,7 +718,7 @@ Checks whether a common event is a sticky one. This API uses a promise to return | |||
| 718 | <!--code_no_check--> | 718 | <!--code_no_check--> |
| 719 | 719 | ||
| 720 | ```ts | 720 | ```ts |
| 721 | -subscriber.isStickyCommonEvent().then((isSticky:boolean) => { | 721 | +subscriber.isStickyCommonEvent().then((isSticky: boolean) => { |
| 722 | console.info(`isStickyCommonEvent ${JSON.stringify(isSticky)}`); | 722 | console.info(`isStickyCommonEvent ${JSON.stringify(isSticky)}`); |
| 723 | }).catch((err: BusinessError) => { | 723 | }).catch((err: BusinessError) => { |
| 724 | console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`); | 724 | console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`); |
| @@ -768,7 +768,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 768 | 768 | ||
| 769 | | ID| Error Message | | 769 | | ID| Error Message | |
| 770 | | -------- | ----------------------------------- | | 770 | | -------- | ----------------------------------- | |
| 771 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 771 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 772 | 772 | ||
| 773 | **Example** | 773 | **Example** |
| 774 | 774 | ||
| @@ -795,7 +795,7 @@ subscriber.finishCommonEvent((err: BusinessError) => { | |||
| 795 | 795 | ||
| 796 | abortCommonEvent(): Promise\<void> | 796 | abortCommonEvent(): Promise\<void> |
| 797 | 797 | ||
| 798 | -Aborts this ordered common event. This API is used with [finishCommonEvent](#finishcommonevent9). After the abort, the common event is not sent to the next subscriber. This API uses a promise to return the result. | 798 | +Aborts an ordered common event. This API is used with [finishCommonEvent](#finishcommonevent9). After the abort, the common event is not sent to the next subscriber. This API uses a promise to return the result. |
| 799 | 799 | ||
| 800 | **System capability**: SystemCapability.Notification.CommonEvent | 800 | **System capability**: SystemCapability.Notification.CommonEvent |
| 801 | 801 | ||
| @@ -863,7 +863,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 863 | 863 | ||
| 864 | | ID| Error Message | | 864 | | ID| Error Message | |
| 865 | | -------- | ----------------------------------- | | 865 | | -------- | ----------------------------------- | |
| 866 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 866 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 867 | 867 | ||
| 868 | **Example** | 868 | **Example** |
| 869 | 869 | ||
| @@ -950,7 +950,7 @@ Checks whether this ordered common event should be aborted. This API uses an asy | |||
| 950 | 950 | ||
| 951 | | Name | Type | Mandatory| Description | | 951 | | Name | Type | Mandatory| Description | |
| 952 | | -------- | ----------------------- | ---- | ---------------------------------- | | 952 | | -------- | ----------------------- | ---- | ---------------------------------- | |
| 953 | -| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. Returns **true** if the ordered common event is in the abort state; returns **false** otherwise.| | 953 | +| callback | AsyncCallback\<boolean> | Yes | If the query is successful, **err** is **undefined**. If **data** is **true**, the ordered common event is aborted. If **data** is **false**, the ordered common event is not aborted. Otherwise, **err** is an error object.| |
| 954 | 954 | ||
| 955 | **Error codes** | 955 | **Error codes** |
| 956 | 956 | ||
| @@ -958,7 +958,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 958 | 958 | ||
| 959 | | ID| Error Message | | 959 | | ID| Error Message | |
| 960 | | -------- | ----------------------------------- | | 960 | | -------- | ----------------------------------- | |
| 961 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 961 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 962 | 962 | ||
| 963 | **Example** | 963 | **Example** |
| 964 | 964 | ||
| @@ -1012,7 +1012,7 @@ Checks whether this ordered common event should be aborted. | |||
| 1012 | 1012 | ||
| 1013 | | Type | Description | | 1013 | | Type | Description | |
| 1014 | | ----------------- | ---------------------------------- | | 1014 | | ----------------- | ---------------------------------- | |
| 1015 | -| boolean |Returns **true** if the ordered common event is in the abort state; returns **false** otherwise.| | 1015 | +| boolean | Returns **true** if the ordered common event is in the abort state; returns **false** otherwise.| |
| 1016 | 1016 | ||
| 1017 | **Example** | 1017 | **Example** |
| 1018 | 1018 | ||
| @@ -1037,7 +1037,7 @@ Obtains the subscriber information. This API uses an asynchronous callback to re | |||
| 1037 | 1037 | ||
| 1038 | | Name | Type | Mandatory| Description | | 1038 | | Name | Type | Mandatory| Description | |
| 1039 | | -------- | ------------------------------------------------------------ | ---- | ---------------------- | | 1039 | | -------- | ------------------------------------------------------------ | ---- | ---------------------- | |
| 1040 | -| callback | AsyncCallback\<[CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md)> | Yes | Callback used to return the result.| | 1040 | +| callback | AsyncCallback\<[CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md)> | Yes | Callback used to return the result. If the subscriber information is successfully obtained, **err** is **undefined** and **data** is the subscription information of the subscriber. Otherwise, **err** is an error object.| |
| 1041 | 1041 | ||
| 1042 | **Error codes** | 1042 | **Error codes** |
| 1043 | 1043 | ||
| @@ -1045,7 +1045,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 1045 | 1045 | ||
| 1046 | | ID| Error Message | | 1046 | | ID| Error Message | |
| 1047 | | -------- | ----------------------------------- | | 1047 | | -------- | ----------------------------------- | |
| 1048 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 1048 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 1049 | 1049 | ||
| 1050 | **Example** | 1050 | **Example** |
| 1051 | 1051 | ||
| @@ -1110,8 +1110,8 @@ Obtains the subscriber information. | |||
| 1110 | <!--code_no_check--> | 1110 | <!--code_no_check--> |
| 1111 | 1111 | ||
| 1112 | ```ts | 1112 | ```ts |
| 1113 | -let subscribeInfo1: commonEventManager.CommonEventSubscribeInfo = subscriber.getSubscribeInfoSync(); | 1113 | +let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = subscriber.getSubscribeInfoSync(); |
| 1114 | -console.info(`Succeeded in getting subscribe info, subscribe info is ${JSON.stringify(subscribeInfo1)}`); | 1114 | +console.info(`Succeeded in getting subscribe info, subscribe info is ${JSON.stringify(subscribeInfo)}`); |
| 1115 | ``` | 1115 | ``` |
| 1116 | 1116 | ||
| 1117 | ### finishCommonEvent<sup>9+</sup> | 1117 | ### finishCommonEvent<sup>9+</sup> |
| @@ -1134,7 +1134,7 @@ For details about the error codes, see [Universal Error Codes](../errorcode-univ | |||
| 1134 | 1134 | ||
| 1135 | | ID| Error Message | | 1135 | | ID| Error Message | |
| 1136 | | -------- | ----------------------------------- | | 1136 | | -------- | ----------------------------------- | |
| 1137 | -| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types.<br>3. Parameter verification failed. | | 1137 | +| 401 | Parameter error. Possible causes:<br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed. | |
| 1138 | 1138 | ||
| 1139 | **Example** | 1139 | **Example** |
| 1140 | 1140 | ||