1e41f4b71Sopenharmony_ci# @ohos.notificationSubscribe (NotificationSubscribe) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **notificationSubscribe** module provides APIs for notification subscription, notification unsubscription, subscription removal, and more. In general cases, only system applications can call these APIs. 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> The APIs provided by this module are system APIs. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Modules to Import 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```ts 14e41f4b71Sopenharmony_ciimport { notificationSubscribe } from '@kit.NotificationKit'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## notificationSubscribe.subscribe 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_cisubscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\<void\>): void 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciSubscribes to a notification with the subscription information specified. This API uses an asynchronous callback to return the result. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**System API**: This is a system API. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Parameters** 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 32e41f4b71Sopenharmony_ci| ---------- | ------------------------- | ---- | ---------------- | 33e41f4b71Sopenharmony_ci| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md#notificationsubscriber) | Yes | Notification subscriber. | 34e41f4b71Sopenharmony_ci| info | [NotificationSubscribeInfo](js-apis-inner-notification-notificationSubscribeInfo-sys.md#notificationsubscribeinfo) | Yes | Notification subscription information. | 35e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**Error codes** 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci| ID | Error Message | 42e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 43e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 44e41f4b71Sopenharmony_ci| 202 | not system app. | 45e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 46e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 47e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 48e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 49e41f4b71Sopenharmony_ci| 1600012 | No memory space. | 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci**Example** 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci```ts 54e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci// subscribe callback 57e41f4b71Sopenharmony_cilet subscribeCallback = (err: BusinessError) => { 58e41f4b71Sopenharmony_ci if (err) { 59e41f4b71Sopenharmony_ci console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); 60e41f4b71Sopenharmony_ci } else { 61e41f4b71Sopenharmony_ci console.info("subscribe success"); 62e41f4b71Sopenharmony_ci } 63e41f4b71Sopenharmony_ci} 64e41f4b71Sopenharmony_cilet onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => { 65e41f4b71Sopenharmony_ci console.info("Consume callback: " + JSON.stringify(data)); 66e41f4b71Sopenharmony_ci} 67e41f4b71Sopenharmony_cilet subscriber: notificationSubscribe.NotificationSubscriber = { 68e41f4b71Sopenharmony_ci onConsume: onConsumeCallback 69e41f4b71Sopenharmony_ci}; 70e41f4b71Sopenharmony_ci// Bundle names are not verified. You need to determine the target bundle names. 71e41f4b71Sopenharmony_cilet info: notificationSubscribe.NotificationSubscribeInfo = { 72e41f4b71Sopenharmony_ci bundleNames: ["bundleName1","bundleName2"] 73e41f4b71Sopenharmony_ci}; 74e41f4b71Sopenharmony_cinotificationSubscribe.subscribe(subscriber, info, subscribeCallback); 75e41f4b71Sopenharmony_ci``` 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci## notificationSubscribe.subscribe 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_cisubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ciSubscribes to notifications of all applications under this user. This API uses an asynchronous callback to return the result. 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci**System API**: This is a system API. 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**Parameters** 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 92e41f4b71Sopenharmony_ci| ---------- | ---------------------- | ---- | ---------------- | 93e41f4b71Sopenharmony_ci| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md#notificationsubscriber) | Yes | Notification subscriber. | 94e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci**Error codes** 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci| ID | Error Message | 101e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 102e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 103e41f4b71Sopenharmony_ci| 202 | not system app. | 104e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 105e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 106e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 107e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 108e41f4b71Sopenharmony_ci| 1600012 | No memory space. | 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci**Example** 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci```ts 113e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_cilet subscribeCallback = (err: BusinessError) => { 116e41f4b71Sopenharmony_ci if (err) { 117e41f4b71Sopenharmony_ci console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); 118e41f4b71Sopenharmony_ci } else { 119e41f4b71Sopenharmony_ci console.info("subscribe success"); 120e41f4b71Sopenharmony_ci } 121e41f4b71Sopenharmony_ci} 122e41f4b71Sopenharmony_cilet onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => { 123e41f4b71Sopenharmony_ci console.info("Consume callback: " + JSON.stringify(data)); 124e41f4b71Sopenharmony_ci} 125e41f4b71Sopenharmony_cilet subscriber: notificationSubscribe.NotificationSubscriber = { 126e41f4b71Sopenharmony_ci onConsume: onConsumeCallback 127e41f4b71Sopenharmony_ci}; 128e41f4b71Sopenharmony_cinotificationSubscribe.subscribe(subscriber, subscribeCallback); 129e41f4b71Sopenharmony_ci``` 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci## notificationSubscribe.subscribe 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_cisubscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): Promise\<void\> 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ciSubscribes to a notification with the subscription information specified. This API uses a promise to return the result. 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci**System API**: This is a system API. 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci**Parameters** 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 148e41f4b71Sopenharmony_ci| ---------- | ------------------------- | ---- | ------------ | 149e41f4b71Sopenharmony_ci| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md#notificationsubscriber) | Yes | Notification subscriber. | 150e41f4b71Sopenharmony_ci| info | [NotificationSubscribeInfo](js-apis-inner-notification-notificationSubscribeInfo-sys.md#notificationsubscribeinfo) | No | Notification subscription information. By default, this parameter is left empty, which means to subscribe to notifications of all applications under this user. | 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci**Return value** 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci| Type | Description | 155e41f4b71Sopenharmony_ci| ------- |------------------| 156e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value. | 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ci**Error codes** 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci| ID | Error Message | 163e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 164e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 165e41f4b71Sopenharmony_ci| 202 | not system app. | 166e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 167e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 168e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 169e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 170e41f4b71Sopenharmony_ci| 1600012 | No memory space. | 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci**Example** 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci```ts 175e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_cilet onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => { 178e41f4b71Sopenharmony_ci console.info("Consume callback: " + JSON.stringify(data)); 179e41f4b71Sopenharmony_ci} 180e41f4b71Sopenharmony_cilet subscriber: notificationSubscribe.NotificationSubscriber = { 181e41f4b71Sopenharmony_ci onConsume: onConsumeCallback 182e41f4b71Sopenharmony_ci}; 183e41f4b71Sopenharmony_cinotificationSubscribe.subscribe(subscriber).then(() => { 184e41f4b71Sopenharmony_ci console.info("subscribe success"); 185e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 186e41f4b71Sopenharmony_ci console.error("subscribe fail: " + JSON.stringify(err)); 187e41f4b71Sopenharmony_ci}); 188e41f4b71Sopenharmony_ci``` 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci## notificationSubscribe.subscribeSelf<sup>11+</sup> 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_cisubscribeSelf(subscriber: NotificationSubscriber): Promise\<void\> 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ciSubscribes to a notification with the subscription information specified. This API uses a promise to return the result. 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci**System API**: This is a system API. 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci**Parameters** 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 204e41f4b71Sopenharmony_ci| ---------- | ------------------------- | ---- | ------------ | 205e41f4b71Sopenharmony_ci| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md#notificationsubscriber) | Yes | Notification subscriber. | 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci**Return value** 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci| Type | Description | 210e41f4b71Sopenharmony_ci| ------- |------------------| 211e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value. | 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci**Error codes** 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci| ID | Error Message | 218e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 219e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 220e41f4b71Sopenharmony_ci| 202 | not system app. | 221e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 222e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 223e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 224e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 225e41f4b71Sopenharmony_ci| 1600012 | No memory space. | 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci**Example** 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci```ts 230e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_cilet onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => { 233e41f4b71Sopenharmony_ci console.info("Consume callback: " + JSON.stringify(data)); 234e41f4b71Sopenharmony_ci} 235e41f4b71Sopenharmony_cilet subscriber: notificationSubscribe.NotificationSubscriber = { 236e41f4b71Sopenharmony_ci onConsume: onConsumeCallback 237e41f4b71Sopenharmony_ci}; 238e41f4b71Sopenharmony_cinotificationSubscribe.subscribeSelf(subscriber).then(() => { 239e41f4b71Sopenharmony_ci console.info("subscribeSelf success"); 240e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 241e41f4b71Sopenharmony_ci console.error("subscribeSelf fail: " + JSON.stringify(err)); 242e41f4b71Sopenharmony_ci}); 243e41f4b71Sopenharmony_ci``` 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci## notificationSubscribe.unsubscribe 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ciunsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ciUnsubscribes from a notification. This API uses an asynchronous callback to return the result. 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci**System API**: This is a system API. 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci**Parameters** 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 262e41f4b71Sopenharmony_ci| ---------- | ---------------------- | ---- | -------------------- | 263e41f4b71Sopenharmony_ci| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md#notificationsubscriber) | Yes | Notification subscriber. | 264e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci**Error codes** 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci| ID | Error Message | 271e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 272e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 273e41f4b71Sopenharmony_ci| 202 | not system app. | 274e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 275e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 276e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 277e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci**Example** 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci```ts 282e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_cilet unsubscribeCallback = (err: BusinessError) => { 285e41f4b71Sopenharmony_ci if (err) { 286e41f4b71Sopenharmony_ci console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`); 287e41f4b71Sopenharmony_ci } else { 288e41f4b71Sopenharmony_ci console.info("unsubscribe success"); 289e41f4b71Sopenharmony_ci } 290e41f4b71Sopenharmony_ci} 291e41f4b71Sopenharmony_cilet onDisconnectCallback = () => { 292e41f4b71Sopenharmony_ci console.info("subscribe disconnect"); 293e41f4b71Sopenharmony_ci} 294e41f4b71Sopenharmony_cilet subscriber: notificationSubscribe.NotificationSubscriber = { 295e41f4b71Sopenharmony_ci onDisconnect: onDisconnectCallback 296e41f4b71Sopenharmony_ci}; 297e41f4b71Sopenharmony_cinotificationSubscribe.unsubscribe(subscriber, unsubscribeCallback); 298e41f4b71Sopenharmony_ci``` 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci## notificationSubscribe.unsubscribe 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ciunsubscribe(subscriber: NotificationSubscriber): Promise\<void\> 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ciUnsubscribes from a notification. This API uses a promise to return the result. 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci**System API**: This is a system API. 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci**Parameters** 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 315e41f4b71Sopenharmony_ci| ---------- | ---------------------- | ---- | ------------ | 316e41f4b71Sopenharmony_ci| subscriber | [NotificationSubscriber](js-apis-inner-notification-notificationSubscriber-sys.md#notificationsubscriber) | Yes | Notification subscriber. | 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci**Return value** 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci| Type | Description | 321e41f4b71Sopenharmony_ci| ------- |------------| 322e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value. | 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci**Error codes** 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci| ID | Error Message | 329e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 330e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 331e41f4b71Sopenharmony_ci| 202 | not system app. | 332e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 333e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 334e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 335e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci**Example** 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci```ts 340e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_cilet onDisconnectCallback = () => { 343e41f4b71Sopenharmony_ci console.info("subscribe disconnect"); 344e41f4b71Sopenharmony_ci} 345e41f4b71Sopenharmony_cilet subscriber: notificationSubscribe.NotificationSubscriber = { 346e41f4b71Sopenharmony_ci onDisconnect: onDisconnectCallback 347e41f4b71Sopenharmony_ci}; 348e41f4b71Sopenharmony_cinotificationSubscribe.unsubscribe(subscriber).then(() => { 349e41f4b71Sopenharmony_ci console.info("unsubscribe success"); 350e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 351e41f4b71Sopenharmony_ci console.error("unsubscribe fail: " + JSON.stringify(err)); 352e41f4b71Sopenharmony_ci}); 353e41f4b71Sopenharmony_ci``` 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ci## notificationSubscribe.remove 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ciremove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason, callback: AsyncCallback\<void\>): void 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ciRemoves a notification based on the bundle information and notification key. This API uses an asynchronous callback to return the result. 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci**System API**: This is a system API. 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci**Parameters** 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 370e41f4b71Sopenharmony_ci| --------------- | ----------------------------------| ---- | -------------------- | 371e41f4b71Sopenharmony_ci| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 372e41f4b71Sopenharmony_ci| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | 373e41f4b71Sopenharmony_ci| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 374e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ci**Error codes** 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci| ID | Error Message | 381e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 382e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 383e41f4b71Sopenharmony_ci| 202 | not system app. | 384e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 385e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 386e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 387e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 388e41f4b71Sopenharmony_ci| 1600007 | The notification is not exist. | 389e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name was not found. | 390e41f4b71Sopenharmony_ci 391e41f4b71Sopenharmony_ci**Example** 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci```ts 394e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 395e41f4b71Sopenharmony_ciimport { notificationManager } from '@kit.NotificationKit'; 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_cilet removeCallback = (err: BusinessError) => { 398e41f4b71Sopenharmony_ci if (err) { 399e41f4b71Sopenharmony_ci console.error(`remove failed, code is ${err.code}, message is ${err.message}`); 400e41f4b71Sopenharmony_ci } else { 401e41f4b71Sopenharmony_ci console.info("remove success"); 402e41f4b71Sopenharmony_ci } 403e41f4b71Sopenharmony_ci} 404e41f4b71Sopenharmony_cilet bundle: notificationManager.BundleOption = { 405e41f4b71Sopenharmony_ci bundle: "bundleName1", 406e41f4b71Sopenharmony_ci}; 407e41f4b71Sopenharmony_cilet notificationKey: notificationSubscribe.NotificationKey = { 408e41f4b71Sopenharmony_ci id: 0, 409e41f4b71Sopenharmony_ci label: "label", 410e41f4b71Sopenharmony_ci}; 411e41f4b71Sopenharmony_cilet reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; 412e41f4b71Sopenharmony_cinotificationSubscribe.remove(bundle, notificationKey, reason, removeCallback); 413e41f4b71Sopenharmony_ci``` 414e41f4b71Sopenharmony_ci 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_ci## notificationSubscribe.remove 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_ciremove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason): Promise\<void\> 420e41f4b71Sopenharmony_ci 421e41f4b71Sopenharmony_ciRemoves a notification based on the bundle information and notification key. This API uses a promise to return the result. 422e41f4b71Sopenharmony_ci 423e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 424e41f4b71Sopenharmony_ci 425e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci**System API**: This is a system API. 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ci**Parameters** 430e41f4b71Sopenharmony_ci 431e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 432e41f4b71Sopenharmony_ci| --------------- | --------------- | ---- | ---------- | 433e41f4b71Sopenharmony_ci| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 434e41f4b71Sopenharmony_ci| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | 435e41f4b71Sopenharmony_ci| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ci**Return value** 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ci| Type | Description | 440e41f4b71Sopenharmony_ci| ------- |------------| 441e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value. | 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_ci**Error codes** 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci| ID | Error Message | 448e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 449e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 450e41f4b71Sopenharmony_ci| 202 | not system app. | 451e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 452e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 453e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 454e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 455e41f4b71Sopenharmony_ci| 1600007 | The notification is not exist. | 456e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name was not found. | 457e41f4b71Sopenharmony_ci 458e41f4b71Sopenharmony_ci**Example** 459e41f4b71Sopenharmony_ci 460e41f4b71Sopenharmony_ci```ts 461e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 462e41f4b71Sopenharmony_ciimport { notificationManager } from '@kit.NotificationKit'; 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_cilet bundle: notificationManager.BundleOption = { 465e41f4b71Sopenharmony_ci bundle: "bundleName1", 466e41f4b71Sopenharmony_ci}; 467e41f4b71Sopenharmony_cilet notificationKey: notificationSubscribe.NotificationKey = { 468e41f4b71Sopenharmony_ci id: 0, 469e41f4b71Sopenharmony_ci label: "label", 470e41f4b71Sopenharmony_ci}; 471e41f4b71Sopenharmony_cilet reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; 472e41f4b71Sopenharmony_cinotificationSubscribe.remove(bundle, notificationKey, reason).then(() => { 473e41f4b71Sopenharmony_ci console.info("remove success"); 474e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 475e41f4b71Sopenharmony_ci console.error("remove fail: " + JSON.stringify(err)); 476e41f4b71Sopenharmony_ci}); 477e41f4b71Sopenharmony_ci``` 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ci## notificationSubscribe.remove 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ciremove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\<void\>): void 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ciRemoves a notification based on the specified unique notification ID. This API uses an asynchronous callback to return the result. 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci**System API**: This is a system API. 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci**Parameters** 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 494e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | -------------------- | 495e41f4b71Sopenharmony_ci| hashCode | string | Yes | Unique notification ID. It is the value of **hashCode** in the [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) object of [SubscribeCallbackData](js-apis-inner-notification-notificationSubscriber-sys.md#subscribecallbackdata) in the [onConsume](js-apis-inner-notification-notificationSubscriber-sys.md#onconsume) callback. | 496e41f4b71Sopenharmony_ci| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 497e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci**Error codes** 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci| ID | Error Message | 504e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 505e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 506e41f4b71Sopenharmony_ci| 202 | not system app. | 507e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 508e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 509e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 510e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 511e41f4b71Sopenharmony_ci| 1600007 | The notification is not exist. | 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_ci**Example** 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ci```ts 516e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_cilet hashCode: string = 'hashCode'; 519e41f4b71Sopenharmony_cilet removeCallback = (err: BusinessError) => { 520e41f4b71Sopenharmony_ci if (err) { 521e41f4b71Sopenharmony_ci console.error(`remove failed, code is ${err.code}, message is ${err.message}`); 522e41f4b71Sopenharmony_ci } else { 523e41f4b71Sopenharmony_ci console.info("remove success"); 524e41f4b71Sopenharmony_ci } 525e41f4b71Sopenharmony_ci} 526e41f4b71Sopenharmony_cilet reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE; 527e41f4b71Sopenharmony_cinotificationSubscribe.remove(hashCode, reason, removeCallback); 528e41f4b71Sopenharmony_ci``` 529e41f4b71Sopenharmony_ci 530e41f4b71Sopenharmony_ci## notificationSubscribe.remove 531e41f4b71Sopenharmony_ci 532e41f4b71Sopenharmony_ciremove(hashCode: string, reason: RemoveReason): Promise\<void\> 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ciRemoves a notification based on the specified unique notification ID. This API uses a promise to return the result. 535e41f4b71Sopenharmony_ci 536e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 537e41f4b71Sopenharmony_ci 538e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 539e41f4b71Sopenharmony_ci 540e41f4b71Sopenharmony_ci**System API**: This is a system API. 541e41f4b71Sopenharmony_ci 542e41f4b71Sopenharmony_ci**Parameters** 543e41f4b71Sopenharmony_ci 544e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 545e41f4b71Sopenharmony_ci| -------- | ---------- | ---- | ---------- | 546e41f4b71Sopenharmony_ci| hashCode | string | Yes | Unique notification ID. | 547e41f4b71Sopenharmony_ci| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 548e41f4b71Sopenharmony_ci 549e41f4b71Sopenharmony_ci**Return value** 550e41f4b71Sopenharmony_ci 551e41f4b71Sopenharmony_ci| Type | Description | 552e41f4b71Sopenharmony_ci| ------- |--| 553e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value. | 554e41f4b71Sopenharmony_ci 555e41f4b71Sopenharmony_ci**Error codes** 556e41f4b71Sopenharmony_ci 557e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_ci| ID | Error Message | 560e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 561e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 562e41f4b71Sopenharmony_ci| 202 | not system app. | 563e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 564e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 565e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 566e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 567e41f4b71Sopenharmony_ci| 1600007 | The notification is not exist. | 568e41f4b71Sopenharmony_ci 569e41f4b71Sopenharmony_ci**Example** 570e41f4b71Sopenharmony_ci 571e41f4b71Sopenharmony_ci```ts 572e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 573e41f4b71Sopenharmony_ci 574e41f4b71Sopenharmony_cilet hashCode: string = 'hashCode'; 575e41f4b71Sopenharmony_cilet reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; 576e41f4b71Sopenharmony_cinotificationSubscribe.remove(hashCode, reason).then(() => { 577e41f4b71Sopenharmony_ci console.info("remove success"); 578e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 579e41f4b71Sopenharmony_ci console.error("remove fail: " + JSON.stringify(err)); 580e41f4b71Sopenharmony_ci}); 581e41f4b71Sopenharmony_ci``` 582e41f4b71Sopenharmony_ci 583e41f4b71Sopenharmony_ci## notificationSubscribe.remove<sup>10+</sup> 584e41f4b71Sopenharmony_ci 585e41f4b71Sopenharmony_ciremove(hashCodes: Array\<String\>, reason: RemoveReason, callback: AsyncCallback\<void\>): void 586e41f4b71Sopenharmony_ci 587e41f4b71Sopenharmony_ciRemoves specified notifications. This API uses an asynchronous callback to return the result. 588e41f4b71Sopenharmony_ci 589e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 592e41f4b71Sopenharmony_ci 593e41f4b71Sopenharmony_ci**System API**: This is a system API. 594e41f4b71Sopenharmony_ci 595e41f4b71Sopenharmony_ci**Parameters** 596e41f4b71Sopenharmony_ci 597e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 598e41f4b71Sopenharmony_ci|-----------|-------------------------------| ---- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 599e41f4b71Sopenharmony_ci| hashCodes | Array\<String\> | Yes | Array of unique notification IDs. It is the value of **hashCode** in the [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) object of [SubscribeCallbackData](js-apis-inner-notification-notificationSubscriber-sys.md#subscribecallbackdata) in the [onConsume](js-apis-inner-notification-notificationSubscriber-sys.md#onconsume) callback. | 600e41f4b71Sopenharmony_ci| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 601e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 602e41f4b71Sopenharmony_ci 603e41f4b71Sopenharmony_ci**Error codes** 604e41f4b71Sopenharmony_ci 605e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 606e41f4b71Sopenharmony_ci 607e41f4b71Sopenharmony_ci| ID | Error Message | 608e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 609e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 610e41f4b71Sopenharmony_ci| 202 | not system app. | 611e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 612e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 613e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 614e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_ci**Example** 617e41f4b71Sopenharmony_ci 618e41f4b71Sopenharmony_ci```ts 619e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_cilet hashCodes: string[] = ['hashCode1', 'hashCode2']; 622e41f4b71Sopenharmony_cilet removeCallback = (err: BusinessError) => { 623e41f4b71Sopenharmony_ci if (err) { 624e41f4b71Sopenharmony_ci console.error(`remove failed, code is ${err.code}, message is ${err.message}`); 625e41f4b71Sopenharmony_ci } else { 626e41f4b71Sopenharmony_ci console.info("remove success"); 627e41f4b71Sopenharmony_ci } 628e41f4b71Sopenharmony_ci} 629e41f4b71Sopenharmony_cilet reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE; 630e41f4b71Sopenharmony_cinotificationSubscribe.remove(hashCodes, reason, removeCallback); 631e41f4b71Sopenharmony_ci``` 632e41f4b71Sopenharmony_ci 633e41f4b71Sopenharmony_ci## notificationSubscribe.remove<sup>10+</sup> 634e41f4b71Sopenharmony_ci 635e41f4b71Sopenharmony_ciremove(hashCodes: Array\<String\>, reason: RemoveReason): Promise\<void\> 636e41f4b71Sopenharmony_ci 637e41f4b71Sopenharmony_ciRemoves specified notifications. This API uses a promise to return the result. 638e41f4b71Sopenharmony_ci 639e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 640e41f4b71Sopenharmony_ci 641e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 642e41f4b71Sopenharmony_ci 643e41f4b71Sopenharmony_ci**System API**: This is a system API. 644e41f4b71Sopenharmony_ci 645e41f4b71Sopenharmony_ci**Parameters** 646e41f4b71Sopenharmony_ci 647e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 648e41f4b71Sopenharmony_ci|-----------|-------------------------------| ---- |-------------| 649e41f4b71Sopenharmony_ci| hashCodes | Array\<String\> | Yes | Array of unique notification IDs. | 650e41f4b71Sopenharmony_ci| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_ci**Return value** 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_ci| Type | Description | 655e41f4b71Sopenharmony_ci| ------- |------------------| 656e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value. | 657e41f4b71Sopenharmony_ci 658e41f4b71Sopenharmony_ci**Error codes** 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci| ID | Error Message | 663e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 664e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 665e41f4b71Sopenharmony_ci| 202 | not system app. | 666e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 667e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 668e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 669e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_ci**Example** 672e41f4b71Sopenharmony_ci 673e41f4b71Sopenharmony_ci```ts 674e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_cilet hashCodes: string[] = ['hashCode1','hashCode2']; 677e41f4b71Sopenharmony_cilet reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; 678e41f4b71Sopenharmony_cinotificationSubscribe.remove(hashCodes, reason).then(() => { 679e41f4b71Sopenharmony_ci console.info("remove success"); 680e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 681e41f4b71Sopenharmony_ci console.error("remove fail: " + JSON.stringify(err)); 682e41f4b71Sopenharmony_ci}); 683e41f4b71Sopenharmony_ci``` 684e41f4b71Sopenharmony_ci 685e41f4b71Sopenharmony_ci## notificationSubscribe.removeAll 686e41f4b71Sopenharmony_ci 687e41f4b71Sopenharmony_ciremoveAll(bundle: BundleOption, callback: AsyncCallback\<void\>): void 688e41f4b71Sopenharmony_ci 689e41f4b71Sopenharmony_ciRemoves all notifications for a specified application. This API uses an asynchronous callback to return the result. 690e41f4b71Sopenharmony_ci 691e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 692e41f4b71Sopenharmony_ci 693e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 694e41f4b71Sopenharmony_ci 695e41f4b71Sopenharmony_ci**System API**: This is a system API. 696e41f4b71Sopenharmony_ci 697e41f4b71Sopenharmony_ci**Parameters** 698e41f4b71Sopenharmony_ci 699e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 700e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | ---------------------------- | 701e41f4b71Sopenharmony_ci| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | Yes | Bundle information of the application. | 702e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 703e41f4b71Sopenharmony_ci 704e41f4b71Sopenharmony_ci**Error codes** 705e41f4b71Sopenharmony_ci 706e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 707e41f4b71Sopenharmony_ci 708e41f4b71Sopenharmony_ci| ID | Error Message | 709e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 710e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 711e41f4b71Sopenharmony_ci| 202 | not system app. | 712e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 713e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 714e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 715e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 716e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name was not found. | 717e41f4b71Sopenharmony_ci 718e41f4b71Sopenharmony_ci**Example** 719e41f4b71Sopenharmony_ci 720e41f4b71Sopenharmony_ci```ts 721e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 722e41f4b71Sopenharmony_ci 723e41f4b71Sopenharmony_cilet removeAllCallback = (err: BusinessError) => { 724e41f4b71Sopenharmony_ci if (err) { 725e41f4b71Sopenharmony_ci console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`); 726e41f4b71Sopenharmony_ci } else { 727e41f4b71Sopenharmony_ci console.info("removeAll success"); 728e41f4b71Sopenharmony_ci } 729e41f4b71Sopenharmony_ci} 730e41f4b71Sopenharmony_cilet bundle: notificationSubscribe.BundleOption = { 731e41f4b71Sopenharmony_ci bundle: "bundleName1", 732e41f4b71Sopenharmony_ci}; 733e41f4b71Sopenharmony_cinotificationSubscribe.removeAll(bundle, removeAllCallback); 734e41f4b71Sopenharmony_ci``` 735e41f4b71Sopenharmony_ci 736e41f4b71Sopenharmony_ci## notificationSubscribe.removeAll 737e41f4b71Sopenharmony_ci 738e41f4b71Sopenharmony_ciremoveAll(callback: AsyncCallback\<void\>): void 739e41f4b71Sopenharmony_ci 740e41f4b71Sopenharmony_ciRemoves all notifications. This API uses an asynchronous callback to return the result. 741e41f4b71Sopenharmony_ci 742e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 743e41f4b71Sopenharmony_ci 744e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 745e41f4b71Sopenharmony_ci 746e41f4b71Sopenharmony_ci**System API**: This is a system API. 747e41f4b71Sopenharmony_ci 748e41f4b71Sopenharmony_ci**Parameters** 749e41f4b71Sopenharmony_ci 750e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 751e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | -------------------- | 752e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 753e41f4b71Sopenharmony_ci 754e41f4b71Sopenharmony_ci**Error codes** 755e41f4b71Sopenharmony_ci 756e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 757e41f4b71Sopenharmony_ci 758e41f4b71Sopenharmony_ci| ID | Error Message | 759e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 760e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 761e41f4b71Sopenharmony_ci| 202 | not system app. | 762e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 763e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 764e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 765e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 766e41f4b71Sopenharmony_ci 767e41f4b71Sopenharmony_ci**Example** 768e41f4b71Sopenharmony_ci 769e41f4b71Sopenharmony_ci```ts 770e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 771e41f4b71Sopenharmony_ci 772e41f4b71Sopenharmony_cilet removeAllCallback = (err: BusinessError) => { 773e41f4b71Sopenharmony_ci if (err) { 774e41f4b71Sopenharmony_ci console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`); 775e41f4b71Sopenharmony_ci } else { 776e41f4b71Sopenharmony_ci console.info("removeAll success"); 777e41f4b71Sopenharmony_ci } 778e41f4b71Sopenharmony_ci} 779e41f4b71Sopenharmony_cinotificationSubscribe.removeAll(removeAllCallback); 780e41f4b71Sopenharmony_ci``` 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_ci## notificationSubscribe.removeAll 783e41f4b71Sopenharmony_ci 784e41f4b71Sopenharmony_ciremoveAll(bundle?: BundleOption): Promise\<void\> 785e41f4b71Sopenharmony_ci 786e41f4b71Sopenharmony_ciRemoves all notifications for a specified application. This API uses a promise to return the result. 787e41f4b71Sopenharmony_ci 788e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 789e41f4b71Sopenharmony_ci 790e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 791e41f4b71Sopenharmony_ci 792e41f4b71Sopenharmony_ci**System API**: This is a system API. 793e41f4b71Sopenharmony_ci 794e41f4b71Sopenharmony_ci**Parameters** 795e41f4b71Sopenharmony_ci 796e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 797e41f4b71Sopenharmony_ci| ------ | ------------ | ---- | ---------- | 798e41f4b71Sopenharmony_ci| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | No | Bundle information of the application. By default, this parameter is left empty, indicating that all notifications will be removed. | 799e41f4b71Sopenharmony_ci 800e41f4b71Sopenharmony_ci**Return value** 801e41f4b71Sopenharmony_ci 802e41f4b71Sopenharmony_ci| Type | Description | 803e41f4b71Sopenharmony_ci| ------- |------------| 804e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value. | 805e41f4b71Sopenharmony_ci 806e41f4b71Sopenharmony_ci**Error codes** 807e41f4b71Sopenharmony_ci 808e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 809e41f4b71Sopenharmony_ci 810e41f4b71Sopenharmony_ci| ID | Error Message | 811e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 812e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 813e41f4b71Sopenharmony_ci| 202 | not system app. | 814e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 815e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 816e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 817e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 818e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name was not found. | 819e41f4b71Sopenharmony_ci 820e41f4b71Sopenharmony_ci**Example** 821e41f4b71Sopenharmony_ci 822e41f4b71Sopenharmony_ci```ts 823e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 824e41f4b71Sopenharmony_ci 825e41f4b71Sopenharmony_ci// If no application is specified, notifications of all applications are deleted. 826e41f4b71Sopenharmony_cinotificationSubscribe.removeAll().then(() => { 827e41f4b71Sopenharmony_ci console.info("removeAll success"); 828e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 829e41f4b71Sopenharmony_ci console.error("removeAll fail: " + JSON.stringify(err)); 830e41f4b71Sopenharmony_ci}); 831e41f4b71Sopenharmony_ci``` 832e41f4b71Sopenharmony_ci 833e41f4b71Sopenharmony_ci## notificationSubscribe.removeAll 834e41f4b71Sopenharmony_ci 835e41f4b71Sopenharmony_ciremoveAll(userId: number, callback: AsyncCallback\<void>): void 836e41f4b71Sopenharmony_ci 837e41f4b71Sopenharmony_ciRemoves all notifications for a specified user. This API uses an asynchronous callback to return the result. 838e41f4b71Sopenharmony_ci 839e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 840e41f4b71Sopenharmony_ci 841e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 842e41f4b71Sopenharmony_ci 843e41f4b71Sopenharmony_ci**System API**: This is a system API. 844e41f4b71Sopenharmony_ci 845e41f4b71Sopenharmony_ci**Parameters** 846e41f4b71Sopenharmony_ci 847e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 848e41f4b71Sopenharmony_ci| ------ | ------------ | ---- | ---------- | 849e41f4b71Sopenharmony_ci| userId | number | Yes | User ID. | 850e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | 851e41f4b71Sopenharmony_ci 852e41f4b71Sopenharmony_ci**Error codes** 853e41f4b71Sopenharmony_ci 854e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 855e41f4b71Sopenharmony_ci 856e41f4b71Sopenharmony_ci| ID | Error Message | 857e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 858e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 859e41f4b71Sopenharmony_ci| 202 | not system app. | 860e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 861e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 862e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 863e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 864e41f4b71Sopenharmony_ci| 1600008 | The user does not exist. | 865e41f4b71Sopenharmony_ci 866e41f4b71Sopenharmony_ci**Example** 867e41f4b71Sopenharmony_ci 868e41f4b71Sopenharmony_ci```ts 869e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 870e41f4b71Sopenharmony_ci 871e41f4b71Sopenharmony_cilet removeAllCallback = (err: BusinessError) => { 872e41f4b71Sopenharmony_ci if (err) { 873e41f4b71Sopenharmony_ci console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`); 874e41f4b71Sopenharmony_ci } else { 875e41f4b71Sopenharmony_ci console.info("removeAll success"); 876e41f4b71Sopenharmony_ci } 877e41f4b71Sopenharmony_ci} 878e41f4b71Sopenharmony_cilet userId: number = 1; 879e41f4b71Sopenharmony_cinotificationSubscribe.removeAll(userId, removeAllCallback); 880e41f4b71Sopenharmony_ci``` 881e41f4b71Sopenharmony_ci 882e41f4b71Sopenharmony_ci## notificationSubscribe.removeAll 883e41f4b71Sopenharmony_ci 884e41f4b71Sopenharmony_ciremoveAll(userId: number): Promise\<void> 885e41f4b71Sopenharmony_ci 886e41f4b71Sopenharmony_ciRemoves all notifications for a specified user. This API uses a promise to return the result. 887e41f4b71Sopenharmony_ci 888e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 889e41f4b71Sopenharmony_ci 890e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER 891e41f4b71Sopenharmony_ci 892e41f4b71Sopenharmony_ci**System API**: This is a system API. 893e41f4b71Sopenharmony_ci 894e41f4b71Sopenharmony_ci**Parameters** 895e41f4b71Sopenharmony_ci 896e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 897e41f4b71Sopenharmony_ci| ------ | ------------ | ---- | ---------- | 898e41f4b71Sopenharmony_ci| userId | number | Yes | User ID. | 899e41f4b71Sopenharmony_ci 900e41f4b71Sopenharmony_ci**Error codes** 901e41f4b71Sopenharmony_ci 902e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Notification Error Codes](./errorcode-notification.md). 903e41f4b71Sopenharmony_ci 904e41f4b71Sopenharmony_ci| ID | Error Message | 905e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 906e41f4b71Sopenharmony_ci| 201 | The application dose not have permission to call the interface. | 907e41f4b71Sopenharmony_ci| 202 | not system app. | 908e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 909e41f4b71Sopenharmony_ci| 1600001 | Internal error. | 910e41f4b71Sopenharmony_ci| 1600002 | Marshalling or unmarshalling error. | 911e41f4b71Sopenharmony_ci| 1600003 | Failed to connect service. | 912e41f4b71Sopenharmony_ci| 1600008 | The user does not exist. | 913e41f4b71Sopenharmony_ci 914e41f4b71Sopenharmony_ci**Example** 915e41f4b71Sopenharmony_ci 916e41f4b71Sopenharmony_ci```ts 917e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 918e41f4b71Sopenharmony_ci 919e41f4b71Sopenharmony_cilet userId: number = 1; 920e41f4b71Sopenharmony_cinotificationSubscribe.removeAll(userId).then(() => { 921e41f4b71Sopenharmony_ci console.info("removeAll success"); 922e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 923e41f4b71Sopenharmony_ci console.error("removeAll fail: " + JSON.stringify(err)); 924e41f4b71Sopenharmony_ci}); 925e41f4b71Sopenharmony_ci``` 926e41f4b71Sopenharmony_ci 927e41f4b71Sopenharmony_ci## NotificationKey 928e41f4b71Sopenharmony_ci 929e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 930e41f4b71Sopenharmony_ci 931e41f4b71Sopenharmony_ci**System API**: This is a system API. 932e41f4b71Sopenharmony_ci 933e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 934e41f4b71Sopenharmony_ci| ----- | ------ | --- | -------- | 935e41f4b71Sopenharmony_ci| id | number | Yes | Notification ID. | 936e41f4b71Sopenharmony_ci| label | string | No | Notification label. This parameter is left empty by default. | 937e41f4b71Sopenharmony_ci 938e41f4b71Sopenharmony_ci## RemoveReason 939e41f4b71Sopenharmony_ci 940e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.Notification 941e41f4b71Sopenharmony_ci 942e41f4b71Sopenharmony_ci**System API**: This is a system API. 943e41f4b71Sopenharmony_ci 944e41f4b71Sopenharmony_ci| Name | Value | Description | 945e41f4b71Sopenharmony_ci| -------------------- | --- | -------------------- | 946e41f4b71Sopenharmony_ci| CLICK_REASON_REMOVE | 1 | The notification is removed after a click on it. | 947e41f4b71Sopenharmony_ci| CANCEL_REASON_REMOVE | 2 | The notification is removed by the user. | 948