js-apis-notificationSubscribe.md 22.8 KB
Newer Older
E
ester.zhou 已提交
1
# @ohos.notificationSubscribe (NotificationSubscribe)
2

E
ester.zhou 已提交
3
The **notificationSubscribe** module provides APIs for notification subscription, notification unsubscription, subscription removal, and more. In general cases, only system applications can call these APIs.
4 5 6 7 8 9 10 11

> **NOTE**
>
> 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.

## Modules to Import

```js
E
ester.zhou 已提交
12
import notificationSubscribe from '@ohos.notificationSubscribe';
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
```



## NotificationSubscribe.subscribe

subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\<void\>): void

Subscribes to a notification with the subscription information specified. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name      | Type                     | Mandatory| Description            |
| ---------- | ------------------------- | ---- | ---------------- |
E
ester.zhou 已提交
33 34
| subscriber | [NotificationSubscriber](js-apis-notification.md#notificationsubscriber)    | Yes  | Notification subscriber.    |
| info       | [NotificationSubscribeInfo](js-apis-notification.md#notificationsubscribeinfo) | Yes  | Notification subscription information.|
35 36 37 38
| callback   | AsyncCallback\<void\>     | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
39 40
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

41 42 43 44 45 46 47 48 49 50 51 52
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

```js
// subscribe callback
function subscribeCallback(err) {
    if (err) {
E
ester.zhou 已提交
53
        console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`);
54 55 56 57 58 59 60
    } else {
        console.info("subscribe success");
    }
}
function onConsumeCallback(data) {
	console.info("Consume callback: " + JSON.stringify(data));
}
E
ester.zhou 已提交
61
let subscriber = {
62
    onConsume: onConsumeCallback
E
ester.zhou 已提交
63 64
};
let info = {
65
    bundleNames: ["bundleName1","bundleName2"]
E
ester.zhou 已提交
66
};
E
ester.zhou 已提交
67
notificationSubscribe.subscribe(subscriber, info, subscribeCallback);
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
```

## NotificationSubscribe.subscribe

subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void

Subscribes to notifications of all applications under this user. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name      | Type                  | Mandatory| Description            |
| ---------- | ---------------------- | ---- | ---------------- |
E
ester.zhou 已提交
86
| subscriber | [NotificationSubscriber](js-apis-notification.md#notificationsubscriber) | Yes  | Notification subscriber.    |
87 88 89 90
| callback   | AsyncCallback\<void\>  | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
91 92
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

93 94 95 96 97 98 99 100 101 102 103
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

```js
function subscribeCallback(err) {
    if (err) {
E
ester.zhou 已提交
104
        console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`);
105 106 107 108 109 110 111
    } else {
        console.info("subscribe success");
    }
}
function onConsumeCallback(data) {
	console.info("Consume callback: " + JSON.stringify(data));
}
E
ester.zhou 已提交
112
let subscriber = {
113
    onConsume: onConsumeCallback
E
ester.zhou 已提交
114
};
E
ester.zhou 已提交
115
notificationSubscribe.subscribe(subscriber, subscribeCallback);
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
```



## NotificationSubscribe.subscribe

subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): Promise\<void\>

Subscribes to a notification with the subscription information specified. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name      | Type                     | Mandatory| Description        |
| ---------- | ------------------------- | ---- | ------------ |
E
ester.zhou 已提交
136 137
| subscriber | [NotificationSubscriber](js-apis-notification.md#notificationsubscriber)    | Yes  | Notification subscriber.|
| info       | [NotificationSubscribeInfo](js-apis-notification.md#notificationsubscribeinfo) | No  | Notification subscription information.  |
138 139 140

**Error codes**

E
ester.zhou 已提交
141 142
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

143 144 145 146 147 148 149 150 151 152 153 154
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

```js
function onConsumeCallback(data) {
    console.info("Consume callback: " + JSON.stringify(data));
}
E
ester.zhou 已提交
155
let subscriber = {
156 157
    onConsume: onConsumeCallback
};
E
ester.zhou 已提交
158
notificationSubscribe.subscribe(subscriber).then(() => {
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
	console.info("subscribe success");
});
```



## NotificationSubscribe.unsubscribe

unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>): void

Unsubscribes from a notification. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name      | Type                  | Mandatory| Description                |
| ---------- | ---------------------- | ---- | -------------------- |
E
ester.zhou 已提交
181
| subscriber | [NotificationSubscriber](js-apis-notification.md#notificationsubscriber) | Yes  | Notification subscriber.        |
182 183 184 185
| callback   | AsyncCallback\<void\>  | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
186 187
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

188 189 190 191 192 193 194 195 196 197 198
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

```js
function unsubscribeCallback(err) {
    if (err) {
E
ester.zhou 已提交
199
        console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`);
200 201 202 203
    } else {
        console.info("unsubscribe success");
    }
}
E
ester.zhou 已提交
204 205
function onDisconnectCallback() {
	console.info("subscribe disconnect");
206
}
E
ester.zhou 已提交
207
let subscriber = {
208
    onDisconnect: onDisconnectCallback
E
ester.zhou 已提交
209
};
E
ester.zhou 已提交
210
notificationSubscribe.unsubscribe(subscriber, unsubscribeCallback);
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
```

## NotificationSubscribe.unsubscribe

unsubscribe(subscriber: NotificationSubscriber): Promise\<void\>

Unsubscribes from a notification. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name      | Type                  | Mandatory| Description        |
| ---------- | ---------------------- | ---- | ------------ |
E
ester.zhou 已提交
229
| subscriber | [NotificationSubscriber](js-apis-notification.md#notificationsubscriber) | Yes  | Notification subscriber.|
230 231 232

**Error codes**

E
ester.zhou 已提交
233 234
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

235 236 237 238 239 240 241 242 243
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

```js
E
ester.zhou 已提交
244 245
function onDisconnectCallback() {
	console.info("subscribe disconnect");
246
}
E
ester.zhou 已提交
247
let subscriber = {
248 249
    onDisconnect: onDisconnectCallback
};
E
ester.zhou 已提交
250
notificationSubscribe.unsubscribe(subscriber).then(() => {
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
	console.info("unsubscribe success");
});
```

## NotificationSubscribe.remove

remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason, callback: AsyncCallback\<void\>): void

Removes a notification for a specified application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name           | Type                               | Mandatory| Description                |
| --------------- |   ----------------------------------| ---- | -------------------- |
E
ester.zhou 已提交
271 272
| bundle          | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption)       | Yes  | Bundle information of the application.          |
| notificationKey | [NotificationKey](js-apis-notification.md#notificationkey) | Yes  | Notification key.            |
273 274 275 276 277
| reason          | [RemoveReason](#removereason)      | Yes  | Reason for removing the notification.        |
| callback        | AsyncCallback\<void\>               | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
278 279
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

280 281 282 283 284 285 286 287 288 289 290 291 292
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 1600007  | The notification is not exist.           |
| 17700001 | The specified bundle name was not found. |

**Example**

```js
function removeCallback(err) {
    if (err) {
E
ester.zhou 已提交
293
        console.error(`remove failed, code is ${err.code}, message is ${err.message}`);
294 295 296 297
    } else {
        console.info("remove success");
    }
}
E
ester.zhou 已提交
298
let bundle = {
299
    bundle: "bundleName1",
E
ester.zhou 已提交
300 301
};
let notificationKey = {
302 303
    id: 0,
    label: "label",
E
ester.zhou 已提交
304
};
E
ester.zhou 已提交
305 306
let reason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
notificationSubscribe.remove(bundle, notificationKey, reason, removeCallback);
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
```



## NotificationSubscribe.remove

remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason): Promise\<void\>

Removes a notification for a specified application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name           | Type           | Mandatory| Description      |
| --------------- | --------------- | ---- | ---------- |
E
ester.zhou 已提交
327
| bundle          | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption)    | Yes  | Bundle information of the application.|
E
ester.zhou 已提交
328
| notificationKey | [NotificationKey](js-apis-notification.md#notificationkey) | Yes  | Notification key.  |
329 330 331 332
| reason          | [RemoveReason](#removereason) | Yes  | Reason for removing the notification.        |

**Error codes**

E
ester.zhou 已提交
333 334
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

335 336 337 338 339 340 341 342 343 344 345
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 1600007  | The notification is not exist.           |
| 17700001 | The specified bundle name was not found. |

**Example**

```js
E
ester.zhou 已提交
346
let bundle = {
347
    bundle: "bundleName1",
E
ester.zhou 已提交
348 349
};
let notificationKey = {
350 351
    id: 0,
    label: "label",
E
ester.zhou 已提交
352
};
E
ester.zhou 已提交
353
let reason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
E
ester.zhou 已提交
354
notificationSubscribe.remove(bundle, notificationKey, reason).then(() => {
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
	console.info("remove success");
});
```

## NotificationSubscribe.remove

remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\<void\>): void

Removes a specified notification. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                 | Mandatory| Description                |
| -------- | --------------------- | ---- | -------------------- |
E
ester.zhou 已提交
375
| hashCode | string                | Yes  | Unique notification ID. It is the **hashCode** in the [NotificationRequest](js-apis-inner-notification-notificationRequest.md#notificationrequest) object of [SubscribeCallbackData](js-apis-notification.md#subscribecallbackdata) of the [onConsume](js-apis-notification.md#onconsume) callback.|
376 377 378 379 380
| reason   | [RemoveReason](#removereason) | Yes  | Reason for removing the notification.        |
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
381 382
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

383 384 385 386 387 388 389 390 391 392
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600007  | The notification is not exist.      |

**Example**

```js
E
ester.zhou 已提交
393
let hashCode = 'hashCode';
394 395 396

function removeCallback(err) {
    if (err) {
E
ester.zhou 已提交
397
        console.error(`remove failed, code is ${err.code}, message is ${err.message}`);
398 399 400 401
    } else {
        console.info("remove success");
    }
}
E
ester.zhou 已提交
402
let reason = notificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE;
E
ester.zhou 已提交
403
notificationSubscribe.remove(hashCode, reason, removeCallback);
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
```

## NotificationSubscribe.remove

remove(hashCode: string, reason: RemoveReason): Promise\<void\>

Removes a specified notification. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type      | Mandatory| Description      |
| -------- | ---------- | ---- | ---------- |
| hashCode | string | Yes  | Unique notification ID.|
| reason   | [RemoveReason](#removereason) | Yes  | Reason for removing the notification.        |

**Error codes**

E
ester.zhou 已提交
427 428
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

429 430 431 432 433 434 435 436 437 438
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600007  | The notification is not exist.      |

**Example**

```js
E
ester.zhou 已提交
439
let hashCode = 'hashCode';
E
ester.zhou 已提交
440 441
let reason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
notificationSubscribe.remove(hashCode, reason).then(() => {
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
	console.info("remove success");
});
```

## NotificationSubscribe.removeAll

removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>): void

Removes all notifications for a specified application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**Parameters**

| Name    | Type                 | Mandatory| Description                        |
| -------- | --------------------- | ---- | ---------------------------- |
E
ester.zhou 已提交
462
| bundle   | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption)        | Yes  | Bundle information of the application.                  |
463 464 465 466
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
467 468
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

469 470 471 472 473 474 475 476 477 478 479 480
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

```js
function removeAllCallback(err) {
    if (err) {
E
ester.zhou 已提交
481
        console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`);
482 483 484 485
    } else {
        console.info("removeAll success");
    }
}
E
ester.zhou 已提交
486
let bundle = {
487
    bundle: "bundleName1",
E
ester.zhou 已提交
488
};
E
ester.zhou 已提交
489
notificationSubscribe.removeAll(bundle, removeAllCallback);
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
```

## NotificationSubscribe.removeAll

removeAll(callback: AsyncCallback\<void\>): void

Removes all notifications. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name    | Type                 | Mandatory| Description                |
| -------- | --------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
512 513
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

514 515 516 517 518 519 520 521 522 523 524
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |

**Example**

```js
function removeAllCallback(err) {
    if (err) {
E
ester.zhou 已提交
525
        console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`);
526 527 528 529 530
    } else {
        console.info("removeAll success");
    }
}

E
ester.zhou 已提交
531
notificationSubscribe.removeAll(removeAllCallback);
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
```

## NotificationSubscribe.removeAll

removeAll(bundle?: BundleOption): Promise\<void\>

Removes all notifications for a specified application. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type        | Mandatory| Description      |
| ------ | ------------ | ---- | ---------- |
E
ester.zhou 已提交
550
| bundle | [BundleOption](js-apis-inner-notification-notificationCommonDef.md#bundleoption) | No  | Bundle information of the application.|
551 552 553

**Error codes**

E
ester.zhou 已提交
554 555
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

556 557 558 559 560 561 562 563 564 565 566
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 1600001  | Internal error.                          |
| 1600002  | Marshalling or unmarshalling error.      |
| 1600003  | Failed to connect service.               |
| 17700001 | The specified bundle name was not found. |

**Example**

```js
// If no application is specified, notifications of all applications are deleted.
E
ester.zhou 已提交
567
notificationSubscribe.removeAll().then(() => {
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
	console.info("removeAll success");
});
```

## NotificationSubscribe.removeAll

removeAll(userId: number, callback: AsyncCallback\<void>): void

Removes all notifications for a specified user. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type        | Mandatory| Description      |
| ------ | ------------ | ---- | ---------- |
| userId | number | Yes  | User ID.|
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

**Error codes**

E
ester.zhou 已提交
593 594
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

595 596 597 598 599 600 601 602 603 604 605 606
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600008  | The user is not exist.              |

**Example**

```js
function removeAllCallback(err) {
    if (err) {
E
ester.zhou 已提交
607
        console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`);
608 609 610 611 612
    } else {
        console.info("removeAll success");
    }
}

E
ester.zhou 已提交
613
let userId = 1;
614

E
ester.zhou 已提交
615
notificationSubscribe.removeAll(userId, removeAllCallback);
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
```

## Notification.removeAll

removeAll(userId: number): Promise\<void>

Removes all notifications for a specified user. This API uses a promise to return the result.

**System capability**: SystemCapability.Notification.Notification

**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type        | Mandatory| Description      |
| ------ | ------------ | ---- | ---------- |
| userId | number | Yes  | User ID.|

**Error codes**

E
ester.zhou 已提交
638 639
For details about the error codes, see [Notification Error Codes](../errorcodes/errorcode-notification.md).

640 641 642 643 644 645 646 647 648 649 650 651
| ID| Error Message                           |
| -------- | ----------------------------------- |
| 1600001  | Internal error.                     |
| 1600002  | Marshalling or unmarshalling error. |
| 1600003  | Failed to connect service.          |
| 1600008  | The user is not exist.              |

**Example**

```js
function removeAllCallback(err) {
    if (err) {
E
ester.zhou 已提交
652
        console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`);
653 654 655 656 657
    } else {
        console.info("removeAll success");
    }
}

E
ester.zhou 已提交
658
let userId = 1;
659

E
ester.zhou 已提交
660
notificationSubscribe.removeAll(userId, removeAllCallback);
661 662
```

E
ester.zhou 已提交
663
## RemoveReason
664 665 666 667 668

**System capability**: SystemCapability.Notification.Notification

**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
669 670 671 672
| Name                | Value | Description                 |
| -------------------- | --- | -------------------- |
| CLICK_REASON_REMOVE  | 1   | The notification is removed after a click on it.   |
| CANCEL_REASON_REMOVE | 2   | The notification is removed by the user.        |