1e41f4b71Sopenharmony_ci# @ohos.commonEventManager (Common Event) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **CommonEventManager** module provides common event capabilities, including the capabilities to publish, subscribe to, and unsubscribe from common events.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> This topic describes only system APIs provided by the module. For details about its public APIs, see [CommonEventManager](./js-apis-commonEventManager.md).
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## Modules to Import
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci```ts
14e41f4b71Sopenharmony_ciimport CommonEventManager from '@ohos.commonEventManager';
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## Support
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciA 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.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciFor details about the enumerations of all system common events, see [System Common Events](./common_event/commonEventManager-definitions.md).
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci## CommonEventManager.publishAsUser<sup>
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_cipublishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): void
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ciPublishes a common event to a specific user. This API uses an asynchronous callback to return the result.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.CommonEvent
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications.
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**Parameters**
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci| Name    | Type                | Mandatory| Description                              |
36e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------- |
37e41f4b71Sopenharmony_ci| event    | string               | Yes  | Name of the common event to publish. For details, see [System Common Events](./common_event/commonEventManager-definitions.md).            |
38e41f4b71Sopenharmony_ci| userId   | number               | Yes  | User ID.|
39e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.            |
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci**Error codes**
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Event Error Codes](./errorcode-CommonEventService.md).
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci| ID| Error Message                           |
46e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
47e41f4b71Sopenharmony_ci| 202      | not system app.                     |  
48e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |  
49e41f4b71Sopenharmony_ci| 1500004  | not System services.                |
50e41f4b71Sopenharmony_ci| 1500007  | error sending message to Common Event Service. |
51e41f4b71Sopenharmony_ci| 1500008  | Common Event Service does not complete initialization. |
52e41f4b71Sopenharmony_ci| 1500009  | error obtaining system parameters.  |
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci**Example**
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci```ts
57e41f4b71Sopenharmony_ciimport Base from '@ohos.base';
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci// Callback for common event publication
60e41f4b71Sopenharmony_cifunction publishCB(err:Base.BusinessError) {
61e41f4b71Sopenharmony_ci	if (err) {
62e41f4b71Sopenharmony_ci        console.error(`publishAsUser failed, code is ${err.code}, message is ${err.message}`);
63e41f4b71Sopenharmony_ci    } else {
64e41f4b71Sopenharmony_ci        console.info("publishAsUser");
65e41f4b71Sopenharmony_ci    }
66e41f4b71Sopenharmony_ci}
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci// Specify the user to whom the common event will be published.
69e41f4b71Sopenharmony_cilet userId = 100;
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci// Publish a common event.
72e41f4b71Sopenharmony_citry {
73e41f4b71Sopenharmony_ci    CommonEventManager.publishAsUser("event", userId, publishCB);
74e41f4b71Sopenharmony_ci} catch (error) {
75e41f4b71Sopenharmony_ci    let err:Base.BusinessError = error as Base.BusinessError;
76e41f4b71Sopenharmony_ci    console.error(`publishAsUser failed, code is ${err.code}, message is ${err.message}`);
77e41f4b71Sopenharmony_ci}
78e41f4b71Sopenharmony_ci```
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci## CommonEventManager.publishAsUser
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_cipublishAsUser(event: string, userId: number, options: CommonEventPublishData, callback: AsyncCallback\<void>): void
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ciPublishes a common event with given attributes to a specific user. This API uses an asynchronous callback to return the result.
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.CommonEvent
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications.
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**Parameters**
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci| Name    | Type                  | Mandatory| Description                  |
93e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ---------------------- |
94e41f4b71Sopenharmony_ci| event    | string                 | Yes  | Name of the common event to publish. For details, see [System Common Events](./common_event/commonEventManager-definitions.md). |
95e41f4b71Sopenharmony_ci| userId   | number | Yes| User ID.|
96e41f4b71Sopenharmony_ci| options  | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | Yes  | Attributes of the common event to publish.|
97e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>   | Yes  | Callback used to return the result. |
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci**Error codes**
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Event Error Codes](./errorcode-CommonEventService.md).
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci| ID| Error Message                           |
104e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
105e41f4b71Sopenharmony_ci| 202      | not system app.                     |  
106e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |  
107e41f4b71Sopenharmony_ci| 1500004  | not System services or System app.                |
108e41f4b71Sopenharmony_ci| 1500007  | error sending message to Common Event Service. |
109e41f4b71Sopenharmony_ci| 1500008  | Common Event Service does not complete initialization. |
110e41f4b71Sopenharmony_ci| 1500009  | error obtaining system parameters.  |
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci**Example**
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci```ts
116e41f4b71Sopenharmony_ciimport Base from '@ohos.base';
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci// Attributes of a common event.
119e41f4b71Sopenharmony_cilet options:CommonEventManager.CommonEventPublishData = {
120e41f4b71Sopenharmony_ci	code: 0,			 // Result code of the common event.
121e41f4b71Sopenharmony_ci	data: "initial data",// Result data of the common event.
122e41f4b71Sopenharmony_ci}
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci// Callback for common event publication
125e41f4b71Sopenharmony_cifunction publishCB(err:Base.BusinessError) {
126e41f4b71Sopenharmony_ci	if (err) {
127e41f4b71Sopenharmony_ci        console.error(`publishAsUser failed, code is ${err.code}, message is ${err.message}`);
128e41f4b71Sopenharmony_ci    } else {
129e41f4b71Sopenharmony_ci        console.info("publishAsUser");
130e41f4b71Sopenharmony_ci    }
131e41f4b71Sopenharmony_ci}
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci// Specify the user to whom the common event will be published.
134e41f4b71Sopenharmony_cilet userId = 100;
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci// Publish a common event.
137e41f4b71Sopenharmony_citry {
138e41f4b71Sopenharmony_ci    CommonEventManager.publishAsUser("event", userId, options, publishCB);
139e41f4b71Sopenharmony_ci} catch (error) {
140e41f4b71Sopenharmony_ci    let err:Base.BusinessError = error as Base.BusinessError;
141e41f4b71Sopenharmony_ci    console.error(`publishAsUser failed, code is ${err.code}, message is ${err.message}`);
142e41f4b71Sopenharmony_ci}
143e41f4b71Sopenharmony_ci```
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci## CommonEventManager.removeStickyCommonEvent<sup>10+</sup>
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ciremoveStickyCommonEvent(event: string, callback: AsyncCallback\<void>): void
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ciRemoves a sticky common event. This API uses an asynchronous callback to return the result.
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.CommonEvent
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.COMMONEVENT_STICKY
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications.
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci**Parameters**
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                            |
160e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | -------------------------------- |
161e41f4b71Sopenharmony_ci| event    | string               | Yes  | Sticky common event to remove. For details, see [System Common Events](./common_event/commonEventManager-definitions.md).      |
162e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci**Error codes**
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Event Error Codes](./errorcode-CommonEventService.md).
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci| ID| Error Message                           |
169e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
170e41f4b71Sopenharmony_ci| 201      | The application dose not have permission to call the interface.     |  
171e41f4b71Sopenharmony_ci| 202      | not system app.                     |  
172e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      |   
173e41f4b71Sopenharmony_ci| 1500004  | not system service.                 |
174e41f4b71Sopenharmony_ci| 1500007  | error sending message to Common Event Service.             |
175e41f4b71Sopenharmony_ci| 1500008  | Common Event Service does not complete initialization.     |
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci**Example**
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci```ts
181e41f4b71Sopenharmony_ciimport Base from '@ohos.base';
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ciCommonEventManager.removeStickyCommonEvent("sticky_event", (err:Base.BusinessError) => {
184e41f4b71Sopenharmony_ci    if (err) {
185e41f4b71Sopenharmony_ci        console.info(`removeStickyCommonEvent failed, errCode: ${err.code}, errMes: ${err.message}`);
186e41f4b71Sopenharmony_ci        return;
187e41f4b71Sopenharmony_ci    }
188e41f4b71Sopenharmony_ci    console.info(`removeStickyCommonEvent success`);
189e41f4b71Sopenharmony_ci});
190e41f4b71Sopenharmony_ci```
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci## CommonEventManager.removeStickyCommonEvent<sup>10+</sup>
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ciremoveStickyCommonEvent(event: string): Promise\<void>
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ciRemoves a sticky common event. This API uses a promise to return the result.
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.CommonEvent
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.COMMONEVENT_STICKY
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications.
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci**Parameters**
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                      |
207e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------- |
208e41f4b71Sopenharmony_ci| event  | string | Yes  | Sticky common event to remove. For details, see [System Common Events](./common_event/commonEventManager-definitions.md).|
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ci**Return value**
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci| Type          | Description                        |
213e41f4b71Sopenharmony_ci| -------------- | ---------------------------- |
214e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result.|
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ci**Error codes**
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Event Error Codes](./errorcode-CommonEventService.md).
219e41f4b71Sopenharmony_ci
220e41f4b71Sopenharmony_ci| ID| Error Message                           |
221e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
222e41f4b71Sopenharmony_ci| 201      | The application dose not have permission to call the interface.     |  
223e41f4b71Sopenharmony_ci| 202      | not system app.                     |  
224e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      | 
225e41f4b71Sopenharmony_ci| 1500004  | not system service.                 |
226e41f4b71Sopenharmony_ci| 1500007  | error sending message to Common Event Service.             |
227e41f4b71Sopenharmony_ci| 1500008  | Common Event Service does not complete initialization.     |
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ci**Example**
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci```ts
233e41f4b71Sopenharmony_ciimport Base from '@ohos.base';
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ciCommonEventManager.removeStickyCommonEvent("sticky_event").then(() => {
236e41f4b71Sopenharmony_ci    console.info(`removeStickyCommonEvent success`);
237e41f4b71Sopenharmony_ci}).catch ((err:Base.BusinessError) => {
238e41f4b71Sopenharmony_ci    console.info(`removeStickyCommonEvent failed, errCode: ${err.code}, errMes: ${err.message}`);
239e41f4b71Sopenharmony_ci});
240e41f4b71Sopenharmony_ci```
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci## CommonEventManager.setStaticSubscriberState<sup>10+</sup>
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_cisetStaticSubscriberState(enable: boolean, callback: AsyncCallback\<void>): void;
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ciEnables or disables static subscription for the current application. This API uses an asynchronous callback to return the result.
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model.
249e41f4b71Sopenharmony_ci
250e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.CommonEvent
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications.
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ci**Parameters**
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                      |
257e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------- |
258e41f4b71Sopenharmony_ci| enable  | boolean | Yes  | Whether static subscription is enabled.<br> **true**: enabled.<br>**false**: disabled.|
259e41f4b71Sopenharmony_ci| callback  | AsyncCallback\<void> | Yes  | Callback used to return the result.|
260e41f4b71Sopenharmony_ci
261e41f4b71Sopenharmony_ci**Error codes**
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Event Error Codes](./errorcode-CommonEventService.md).
264e41f4b71Sopenharmony_ci
265e41f4b71Sopenharmony_ci| ID| Error Message                           |
266e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
267e41f4b71Sopenharmony_ci| 202      | not system app.                     |  
268e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      | 
269e41f4b71Sopenharmony_ci| 1500007  | error sending message to Common Event Service.             |
270e41f4b71Sopenharmony_ci| 1500008  | Common Event Service does not complete initialization.     |
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ci**Example**
273e41f4b71Sopenharmony_ci
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci```ts
276e41f4b71Sopenharmony_ciimport Base from '@ohos.base';
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ciCommonEventManager.setStaticSubscriberState(true, (err:Base.BusinessError) => {
279e41f4b71Sopenharmony_ci    if (!err) {
280e41f4b71Sopenharmony_ci        console.info(`setStaticSubscriberState failed, err is null.`);
281e41f4b71Sopenharmony_ci        return;
282e41f4b71Sopenharmony_ci    }
283e41f4b71Sopenharmony_ci    if (err.code !== undefined && err.code != null) {
284e41f4b71Sopenharmony_ci        console.info(`setStaticSubscriberState failed, errCode: ${err.code}, errMes: ${err.message}`);
285e41f4b71Sopenharmony_ci        return;
286e41f4b71Sopenharmony_ci    }
287e41f4b71Sopenharmony_ci    console.info(`setStaticSubscriberState success`);
288e41f4b71Sopenharmony_ci});
289e41f4b71Sopenharmony_ci```
290e41f4b71Sopenharmony_ci
291e41f4b71Sopenharmony_ci## CommonEventManager.setStaticSubscriberState<sup>10+</sup>
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_cisetStaticSubscriberState(enable: boolean): Promise\<void>;
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ciEnables or disables static subscription for the current application. This API uses a promise to return the result.
296e41f4b71Sopenharmony_ci
297e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model.
298e41f4b71Sopenharmony_ci
299e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.CommonEvent
300e41f4b71Sopenharmony_ci
301e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications.
302e41f4b71Sopenharmony_ci
303e41f4b71Sopenharmony_ci**Parameters**
304e41f4b71Sopenharmony_ci
305e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                      |
306e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------- |
307e41f4b71Sopenharmony_ci| enable  | boolean | Yes  | Whether static subscription is enabled.<br> **true**: enabled.<br>**false**: disabled.|
308e41f4b71Sopenharmony_ci
309e41f4b71Sopenharmony_ci**Return value**
310e41f4b71Sopenharmony_ci
311e41f4b71Sopenharmony_ci| Type          | Description                        |
312e41f4b71Sopenharmony_ci| -------------- | ---------------------------- |
313e41f4b71Sopenharmony_ci| Promise\<void> |  Promise that returns no value.|
314e41f4b71Sopenharmony_ci
315e41f4b71Sopenharmony_ci**Error codes**
316e41f4b71Sopenharmony_ci
317e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Event Error Codes](./errorcode-CommonEventService.md).
318e41f4b71Sopenharmony_ci
319e41f4b71Sopenharmony_ci| ID| Error Message                           |
320e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
321e41f4b71Sopenharmony_ci| 202      | not system app.                     |  
322e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      | 
323e41f4b71Sopenharmony_ci| 1500007  | error sending message to Common Event Service.             |
324e41f4b71Sopenharmony_ci| 1500008  | Common Event Service does not complete initialization.     |
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ci**Example**
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci```ts
330e41f4b71Sopenharmony_ciimport Base from '@ohos.base';
331e41f4b71Sopenharmony_ci
332e41f4b71Sopenharmony_ciCommonEventManager.setStaticSubscriberState(false).then(() => {
333e41f4b71Sopenharmony_ci    console.info(`setStaticSubscriberState success`);
334e41f4b71Sopenharmony_ci}).catch ((err:Base.BusinessError) => {
335e41f4b71Sopenharmony_ci    console.info(`setStaticSubscriberState failed, errCode: ${err.code}, errMes: ${err.message}`);
336e41f4b71Sopenharmony_ci});
337e41f4b71Sopenharmony_ci```
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ci## CommonEventManager.setStaticSubscriberState<sup>12+</sup>
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_cisetStaticSubscriberState(enable: boolean, events?: Array<string>): Promise<void>
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ciEnables or disables the static subscription event for the current application and records the event name. This API uses a promise to return the result.
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model.
346e41f4b71Sopenharmony_ci
347e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.CommonEvent
348e41f4b71Sopenharmony_ci
349e41f4b71Sopenharmony_ci**System API**: This is a system API.
350e41f4b71Sopenharmony_ci
351e41f4b71Sopenharmony_ci**Parameters**
352e41f4b71Sopenharmony_ci
353e41f4b71Sopenharmony_ci| Name| Type         | Mandatory| Description                                                |
354e41f4b71Sopenharmony_ci| ------ | ------------- | ---- | ---------------------------------------------------- |
355e41f4b71Sopenharmony_ci| enable | boolean       | Yes  | Whether static subscription is enabled.<br> **true**: enabled.<br>**false**: disabled.|
356e41f4b71Sopenharmony_ci| events | array<string> | No  | Name of a recorded event.                                  |
357e41f4b71Sopenharmony_ci
358e41f4b71Sopenharmony_ci**Return value**
359e41f4b71Sopenharmony_ci
360e41f4b71Sopenharmony_ci| Type          | Description                                |
361e41f4b71Sopenharmony_ci| -------------- | ------------------------------------ |
362e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.|
363e41f4b71Sopenharmony_ci
364e41f4b71Sopenharmony_ci**Error codes**
365e41f4b71Sopenharmony_ci
366e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Event Error Codes](./errorcode-CommonEventService.md).
367e41f4b71Sopenharmony_ci
368e41f4b71Sopenharmony_ci| ID| Error Message                                              |
369e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------ |
370e41f4b71Sopenharmony_ci| 202      | not system app.                     |  
371e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.      | 
372e41f4b71Sopenharmony_ci| 1500007  | error sending message to Common Event Service.         |
373e41f4b71Sopenharmony_ci| 1500008  | Common Event Service does not complete initialization. |
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ci**Example**
376e41f4b71Sopenharmony_ci
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci```ts
379e41f4b71Sopenharmony_ciimport Base from '@ohos.base'
380e41f4b71Sopenharmony_ciimport promptAction from '@ohos.promptAction'
381e41f4b71Sopenharmony_ciimport CommonEventManager from '@ohos.commonEventManager'
382e41f4b71Sopenharmony_ci
383e41f4b71Sopenharmony_cilet evenName: string[] = ['usual.event.SEND_DATA'];
384e41f4b71Sopenharmony_ciCommonEventManager.setStaticSubscriberState(true, evenName).then(() => {
385e41f4b71Sopenharmony_ci  try {
386e41f4b71Sopenharmony_ci    promptAction.showToast({
387e41f4b71Sopenharmony_ci      message: 'app.string.static_subscribe_enabled',
388e41f4b71Sopenharmony_ci      duration: 2000,
389e41f4b71Sopenharmony_ci    });
390e41f4b71Sopenharmony_ci  } catch (error) {
391e41f4b71Sopenharmony_ci    console.error(`showToast error code is ${error.code}, message is ${error.message}`);
392e41f4b71Sopenharmony_ci  }
393e41f4b71Sopenharmony_ci  console.info(`setStaticSubscriberState success, state is ${true}`);
394e41f4b71Sopenharmony_ci}).catch((err: Base.BusinessError) => {
395e41f4b71Sopenharmony_ci  console.info(`setStaticSubscriberState failed, errCode: ${err.code}, errMes: ${err.message}`);
396e41f4b71Sopenharmony_ci});
397e41f4b71Sopenharmony_ci```
398