文档管理中心

发布进度条类型通知

进度条通知也是常见的通知类型,主要应用于文件下载、事务处理进度显示。当前系统提供了进度条模板,发布通知应用应设置好进度条模板的属性值,如模板名、模板数据,通过通知子系统发送到通知栏显示。

目前系统模板仅支持进度条模板,通知模板NotificationTemplate中的data参数为用户自定义数据,用于显示与模板相关的数据。

接口说明

isSupportTemplate()是查询是否支持对应的通知模板,目前仅支持进度条模板。

展开
接口名 描述
isSupportTemplate(templateName: string): Promise<boolean> 查询是否支持对应的通知模板。

开发步骤

  1. 导入模块。

    收起
    自动换行
    深色代码主题
    复制
    1. import { notificationManager } from '@kit.NotificationKit';
    2. import { BusinessError } from '@kit.BasicServicesKit';
    3. import { hilog } from '@kit.PerformanceAnalysisKit';
    4. const TAG: string = '[PublishOperation]';
    5. const DOMAIN_NUMBER: number = 0xFF00;
  2. 查询系统是否支持进度条模板,查询结果为支持downloadTemplate模板类通知。

    收起
    自动换行
    深色代码主题
    复制
    1. notificationManager.isSupportTemplate('downloadTemplate').then((data: boolean) => {
    2. let isSupportTemplate: boolean = data; // isSupportTemplate的值为true表示支持downloadTemplate模板类通知,false表示不支持
    3. hilog.info(DOMAIN_NUMBER, TAG,
    4. `Succeeded in supporting download template notification. data is ${isSupportTemplate}`);
    5. }).catch((err: BusinessError) => {
    6. hilog.error(DOMAIN_NUMBER, TAG,
    7. `Failed to support download template notification. Code is ${err.code}, message is ${err.message}`);
    8. });
    说明

    查询系统支持进度条模板后,再进行后续的步骤操作。

  3. 构造进度条模板对象,并发布通知。

    收起
    自动换行
    深色代码主题
    复制
    1. let notificationRequest: notificationManager.NotificationRequest = {
    2. id: 5,
    3. content: {
    4. notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
    5. normal: {
    6. title: 'test_title',
    7. text: 'test_text',
    8. additionalText: 'test_additionalText'
    9. }
    10. },
    11. // 构造进度条模板,name字段当前需要固定配置为downloadTemplate
    12. template: {
    13. name: 'downloadTemplate',
    14. data: { title: 'File Title', fileName: 'music.mp4', progressValue: 45 }
    15. }
    16. };
    17. // 发布通知
    18. notificationManager.publish(notificationRequest, (err: BusinessError) => {
    19. if (err) {
    20. hilog.error(DOMAIN_NUMBER, TAG,
    21. `Failed to publish notification. Code is ${err.code}, message is ${err.message}`);
    22. return;
    23. }
    24. hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.');
    25. });