当前位置: 首页 > news >正文

鸿蒙 DevEcoStudio:发布进度条通知

使用notificationManager及wantAgent实现功能import notificationManager from '@ohos.notificationManager'
import wantAgent from '@ohos.app.ability.wantAgent'
@Entry
@Component
struct Index {@State message: string = '发布进度条通知'progressValue: number=0async publicDownloadNotiication(){// 导入模块notificationManager// notificationManager//行为意图let wantInfo:wantAgent.WantAgentInfo={wants:[{bundleName:'com.example.myapplication',  //跳转哪个应用abilityName:'EntryAbility'  //跳转应用后哪个ability} //使用大括号封装不同的功能],operationType:wantAgent.OperationType.START_ABILITY,  //START_ABILITY 启动abilityrequestCode:0}//创建实例对象let wantInstance=await wantAgent.getWantAgent(wantInfo)let isSupport=notificationManager.isSupportTemplate('downloadTemplate')  //当前系统是否支持.then(()=>{console.log('成功')}).catch(()=>{console.log('失败')})if (!isSupport) {return}let template={name:'downloadTemplate', //设置进度条data:{progressValue:this.progressValue,progressMaxValue:100  //设置一个最大值progressMaxValue}}let notificationRequest:notificationManager.NotificationRequest={id:1,template:template,  //加入进度条,由普通通知变为有进度条的wantAgent:wantInstance,content:{contentType:notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, //设置普通通知normal:{title:'下载中',text:'',additionalText:`${this.progressValue}%`  //进度百分之多少,引号使用Tab键上边的那个波浪键}}}notificationManager.publish(notificationRequest)}build() {Row() {Column() {Text(this.message).fontSize(50).fontWeight(FontWeight.Bold).onClick(()=>{// 添加一个定时器,模拟每过5s进度条增加20%的动态效果this.publicDownloadNotiication()let taskid=setInterval(()=>{if (this.progressValue>=80) {clearInterval(taskid)   //clearInterval清除}this.progressValue+=20this.publicDownloadNotiication()},5000)  //5s})}.width('100%')}.height('100%')}
}

实际效果图:

http://www.lryc.cn/news/356363.html

相关文章:

  • web前端之vue动态访问静态资源、静态资源的动态访问、打包、public、import、URL、Vite
  • Raven2掠夺者2渡鸦2角色创建、游戏预下载、账号怎么注册教程
  • Window VScode配置Conda教程(成功版)
  • 探索旅行的优惠之选,千益畅行旅游卡让旅程更省心省力!
  • JVM学习-彻底搞懂Java自增++
  • 【全开源】民宿酒店预订管理系统(ThinkPHP+uniapp+uView)
  • 9.3 Go语言入门(变量声明和函数调用)
  • CVE-2020-7982 OpenWrt 远程命令执行漏洞学习(更新中)
  • 代码随想录——左叶子之和(Leetcode404)
  • 解禁谷歌等浏览器禁止网站使用麦克等媒体设备
  • 如何彻底卸载sql sever2022
  • 「51媒体」如何与媒体建立良好关系?
  • Selenium 库的爬虫实现
  • 【文末附gpt升级方案】数据虚拟化技术的优势
  • C++ 常量和变量
  • 【cocos creator 】生成六边形地图
  • TypeScript类型体操练习
  • leetcode231-Power of Two
  • 贪心算法简单介绍
  • 眼底项目经验
  • 使用arco design实现动态列信息的表格
  • 解决 fatal: Not a git repository (or any of the parent directories): .git 问题
  • Spring 模拟管理Web应用程序
  • 修改了vue3 <script setup>留言板
  • jQuery 常用API
  • 内网安全-隧道搭建穿透上线内网穿透-nps自定义上线内网渗透-Linux上线-cs上线Linux主机
  • 【AHK V2】设计模式之命令模式
  • 2024年5月20日 (周二) 叶子游戏新闻
  • 【SQL学习进阶】从入门到高级应用(二)
  • FL Studio v21.2.3.4004中文破解版百度网盘下载