• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Publishing a Progress Notification
2<!--Kit: Notification Kit-->
3<!--Subsystem: Notification-->
4<!--Owner: @michael_woo888-->
5<!--Designer: @dongqingran; @wulong158-->
6<!--Tester: @wanghong1997-->
7<!--Adviser: @huipeizi-->
8
9The progress notification is a commonly used notification type, mainly used to display the progress of an ongoing operation, such as file downloading. When publishing a progress notification through the notification subsystem, you can use the readily available template by specifying the related attributes, such as the template name and template data.
10
11In the [NotificationTemplate](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-notification-kit/js-apis-inner-notification-notificationTemplate.md), which can only be of the progress type, **data** indicates custom template data.
12
13## Available APIs
14
15[isSupportTemplate()](../reference/apis-notification-kit/js-apis-notificationManager.md#notificationmanagerissupporttemplate) is used to check whether a specific template is supported. Currently, only the progress bar template is supported.
16
17| Name| Description|
18| -------- | -------- |
19| isSupportTemplate(templateName: string): Promise\<boolean\> | Checks whether a specific template is supported.|
20
21
22## How to Develop
23
241. Import the module.
25
26   ```ts
27   import { notificationManager } from '@kit.NotificationKit';
28   import { BusinessError } from '@kit.BasicServicesKit';
29   import { hilog } from '@kit.PerformanceAnalysisKit';
30
31   const TAG: string = '[PublishOperation]';
32   const DOMAIN_NUMBER: number = 0xFF00;
33   ```
34
352. Check whether a specific template is supported. In this example, the template of the **downloadTemplate** type is checked.
36
37   ```ts
38   notificationManager.isSupportTemplate('downloadTemplate').then((data:boolean) => {
39     let isSupportTpl: boolean = data; // The value true means that the template of the downloadTemplate type is supported, and false means the opposite.
40     hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in supporting download template notification. data is ${isSupportTpl}`);
41   }).catch((err: BusinessError) => {
42     hilog.error(DOMAIN_NUMBER, TAG, `Failed to support download template notification. Code is ${err.code}, message is ${err.message}`);
43   });
44   ```
45
46   > **NOTE**
47   > Proceed with the step below only when the specified template is supported.
48
493. Create a **NotificationRequest** object and publish a progress notification.
50
51   ```ts
52   let notificationRequest: notificationManager.NotificationRequest = {
53     id: 5,
54     content: {
55       notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
56       normal: {
57         title: 'test_title',
58         text: 'test_text',
59         additionalText: 'test_additionalText'
60       }
61     },
62     // Create a progress template. The name field has a fixed value of downloadTemplate.
63     template: {
64       name: 'downloadTemplate',
65       data: { title: 'File Title', fileName: 'music.mp4', progressValue: 45 }
66     }
67   }
68
69   // Publish the notification.
70   notificationManager.publish(notificationRequest, (err: BusinessError) => {
71     if (err) {
72       hilog.error(DOMAIN_NUMBER, TAG, `Failed to publish notification. Code is ${err.code}, message is ${err.message}`);
73       return;
74     }
75     hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.');
76   });
77   ```
78