1# Canceling a Notification 2 3When a user taps a notification and starts the application in the foreground, the application can cancel one or all notifications. 4 5For example, after a user receives an IM from a friend and taps a notification to view the message, the application can cancel the notification. 6 7## Available APIs 8 9The table below lists some APIs for canceling notifications. For details about the APIs, see [@ohos.notificationManager (NotificationManager)](../reference/apis-notification-kit/js-apis-notificationManager.md). 10 11| **API**| **Description**| 12| -------- | -------- | 13| cancel(id: number, callback: AsyncCallback<void>): void | Cancels a notification. | 14| cancelAll(callback: AsyncCallback<void>): void | Cancels all notifications published by the application.| 15 16 17## How to Develop 18 19The following describes how to cancel a text notification. This procedure is applicable for canceling other types of notifications. 20 211. Import modules. 22 23 ```ts 24 import { notificationManager } from '@kit.NotificationKit'; 25 import { BusinessError } from '@kit.BasicServicesKit'; 26 import { hilog } from '@kit.PerformanceAnalysisKit'; 27 28 const TAG: string = '[PublishOperation]'; 29 const DOMAIN_NUMBER: number = 0xFF00; 30 ``` 31 322. Publish a notification. 33 34 For details, see [Publishing a Text Notification](./text-notification.md). 35 363. Cancel the notification. 37 38 ```ts 39 // After the application is started in the foreground and the message is viewed, call this API to cancel the notification. 40 notificationManager.cancel(1, (err: BusinessError) => { 41 if (err) { 42 hilog.error(DOMAIN_NUMBER, TAG, `Failed to cancel notification. Code is ${err.code}, message is ${err.message}`); 43 return; 44 } 45 hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in canceling notification.'); 46 }); 47 ``` 48