1e41f4b71Sopenharmony_ci# Publishing a Text Notification
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciYou can publish text notifications to send SMS messages, alert messages, and more. There are two types of text notifications: normal text and multi-line text.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci**Table 1** Basic notification content types
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci| Type                            | Description         |
8e41f4b71Sopenharmony_ci| ------------------------------- | ------------- |
9e41f4b71Sopenharmony_ci| NOTIFICATION_CONTENT_BASIC_TEXT | Normal text notification.|
10e41f4b71Sopenharmony_ci| NOTIFICATION_CONTENT_MULTILINE  | Multi-line text notification.|
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci## Available APIs
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ciThe following table describes the APIs for notification publishing. You specify the notification information – content, ID, slot type, and publish time – by setting the [NotificationRequest](../reference/apis-notification-kit/js-apis-inner-notification-notificationRequest.md#notificationrequest) parameter in the APIs.
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci| Name| Description|
17e41f4b71Sopenharmony_ci| -------- | -------- |
18e41f4b71Sopenharmony_ci| publish(request: NotificationRequest, callback: AsyncCallback<void>): void | Publishes a notification.                |
19e41f4b71Sopenharmony_ci| cancel(id: number, label: string, callback: AsyncCallback<void>): void | Cancels a notification.          |
20e41f4b71Sopenharmony_ci| cancelAll(callback: AsyncCallback<void>): void | Cancels all notifications published by the application.|
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci## How to Develop
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci1. Import the module.
26e41f4b71Sopenharmony_ci   
27e41f4b71Sopenharmony_ci   ```ts
28e41f4b71Sopenharmony_ci   import { notificationManager } from '@kit.NotificationKit';
29e41f4b71Sopenharmony_ci   import { BusinessError } from '@kit.BasicServicesKit';
30e41f4b71Sopenharmony_ci   import { hilog } from '@kit.PerformanceAnalysisKit';
31e41f4b71Sopenharmony_ci   
32e41f4b71Sopenharmony_ci   const TAG: string = '[PublishOperation]';
33e41f4b71Sopenharmony_ci   const DOMAIN_NUMBER: number = 0xFF00;
34e41f4b71Sopenharmony_ci   ```
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci2. Create a **NotificationRequest** object and publish a progress notification.
37e41f4b71Sopenharmony_ci   - A normal text notification consists of the **title**, **text**, and **additionalText** parameters, of which **title** and **text** are mandatory. The value of these parameters contains less than 200 bytes. Excess content will be truncated.
38e41f4b71Sopenharmony_ci     
39e41f4b71Sopenharmony_ci      ```ts
40e41f4b71Sopenharmony_ci      let notificationRequest: notificationManager.NotificationRequest = {
41e41f4b71Sopenharmony_ci        id: 1,
42e41f4b71Sopenharmony_ci        content: {
43e41f4b71Sopenharmony_ci          notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, // Basic notification
44e41f4b71Sopenharmony_ci          normal: {
45e41f4b71Sopenharmony_ci            title: 'test_title',
46e41f4b71Sopenharmony_ci            text: 'test_text',
47e41f4b71Sopenharmony_ci            additionalText: 'test_additionalText',
48e41f4b71Sopenharmony_ci          }
49e41f4b71Sopenharmony_ci        }
50e41f4b71Sopenharmony_ci      };
51e41f4b71Sopenharmony_ci      notificationManager.publish(notificationRequest, (err: BusinessError) => {
52e41f4b71Sopenharmony_ci        if (err) {
53e41f4b71Sopenharmony_ci          hilog.error(DOMAIN_NUMBER, TAG, `Failed to publish notification. Code is ${err.code}, message is ${err.message}`);
54e41f4b71Sopenharmony_ci          return;
55e41f4b71Sopenharmony_ci        }
56e41f4b71Sopenharmony_ci        hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.');
57e41f4b71Sopenharmony_ci      });
58e41f4b71Sopenharmony_ci      ```
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci   - In addition to the parameters in the normal text notification, the multi-line text notification provides the **lines**, **briefText**, and **longTitle** parameters. The value of these parameters contains less than 200 bytes. Excess content will be truncated. By default, a multi-line notification looks in the same way as a normal text notification. When expanded, the notification displays the title and content specified in **longTitle** and **lines**, respectively.
62e41f4b71Sopenharmony_ci     
63e41f4b71Sopenharmony_ci      ```ts
64e41f4b71Sopenharmony_ci      let notificationRequest: notificationManager.NotificationRequest = {
65e41f4b71Sopenharmony_ci        id: 3,
66e41f4b71Sopenharmony_ci        content: {
67e41f4b71Sopenharmony_ci          notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_MULTILINE, // Multi-line text notification
68e41f4b71Sopenharmony_ci          multiLine: {
69e41f4b71Sopenharmony_ci            title: 'test_title',
70e41f4b71Sopenharmony_ci            text: 'test_text',
71e41f4b71Sopenharmony_ci            briefText: 'test_briefText',
72e41f4b71Sopenharmony_ci            longTitle: 'test_longTitle',
73e41f4b71Sopenharmony_ci            lines: ['line_01', 'line_02', 'line_03', 'line_04'],
74e41f4b71Sopenharmony_ci          }
75e41f4b71Sopenharmony_ci        }
76e41f4b71Sopenharmony_ci      };
77e41f4b71Sopenharmony_ci      // Publish the notification.
78e41f4b71Sopenharmony_ci      notificationManager.publish(notificationRequest, (err: BusinessError) => {
79e41f4b71Sopenharmony_ci        if (err) {
80e41f4b71Sopenharmony_ci          hilog.error(DOMAIN_NUMBER, TAG, `Failed to publish notification. Code is ${err.code}, message is ${err.message}`);
81e41f4b71Sopenharmony_ci          return;
82e41f4b71Sopenharmony_ci        }
83e41f4b71Sopenharmony_ci        hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.');
84e41f4b71Sopenharmony_ci      });
85e41f4b71Sopenharmony_ci      ```
86e41f4b71Sopenharmony_ci3. Delete the notification.
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci   ```ts
89e41f4b71Sopenharmony_ci    notificationManager.cancel(1, (err: BusinessError) => {
90e41f4b71Sopenharmony_ci      if (err) {
91e41f4b71Sopenharmony_ci        hilog.error(DOMAIN_NUMBER, TAG, `Failed to cancel notification. Code is ${err.code}, message is ${err.message}`);
92e41f4b71Sopenharmony_ci        return;
93e41f4b71Sopenharmony_ci      }
94e41f4b71Sopenharmony_ci      hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in cancel notification.');
95e41f4b71Sopenharmony_ci    });
96e41f4b71Sopenharmony_ci   ```
97