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

鸿蒙 DevEcoStudio:通知栏通知实现

【使用notificationManager实现通知栏功能】

【普通通知、长文本通知、多行通知、图片通知】

import notificationManager from '@ohos.notificationManager'
import image from '@ohos.multimedia.image'
@Entry
@Component
struct Index {@State message: string = 'Hello World'// 将图片转换为PixelMap对象imagePixelMap: PixelMap=undefinedasync aboutToAppear(){//   获取资源管理器let rm=getContext(this).resourceManager// 读取图片let file=await rm.getMediaContent($r('app.media.app_icon'))//   创建PixelMapimage.createImageSource(file.buffer).createPixelMap().then(value=>{this.imagePixelMap=value})}build() {Row() {Column() {// 普通通知Text('发布普通通知1').fontSize(50).fontWeight(FontWeight.Bold).onClick(()=>{let notificationRequest: notificationManager.NotificationRequest={id:1,content:{contentType:notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,normal:{title:'普通通知标题1',text:'普通通知内容',additionalText:'附加内容'}}}notificationManager.publish(notificationRequest)})Text('发布普通通知2').fontSize(50).fontWeight(FontWeight.Bold).onClick(()=>{let notificationRequest: notificationManager.NotificationRequest={id:2,content:{contentType:notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,normal:{title:'普通通知标题2',text:'普通通知内容2',additionalText:'附加内容'}}}notificationManager.publish(notificationRequest)})Text('取消普通通知').onClick(()=>{notificationManager.cancel(1)})Text('取消全部通知').onClick(()=>{notificationManager.cancelAll()})// 长文本通知Text('发布长文本通知').onClick(()=>{let notificationRequest: notificationManager.NotificationRequest={id:3,content:{contentType:notificationManager.ContentType.NOTIFICATION_CONTENT_LONG_TEXT,longText:{title:'长文本通知标题',text:'长文本内容',additionalText:'附加内容',expandedTitle:'展开后标题',briefText: 'text_long',longText:'展开后内容(凑内容:sdwdwiifjewifjwiejfiwjfiwejfiwejfwefjwiejwgwg)'}}}notificationManager.publish(notificationRequest)})// 多行通知Text('发布多行通知').onClick(()=>{let notificationRequest: notificationManager.NotificationRequest={id:4,content:{contentType:notificationManager.ContentType.NOTIFICATION_CONTENT_MULTILINE,multiLine:{title:'多行通知标题',text:'多行通知内容',additionalText:'附加',briefText:'text_mul',longTitle:'展开标题',lines:['第一行','第二行','第三行','第四行']}}}notificationManager.publish(notificationRequest)})// 图片类型通知(图片内容为PixelMap型对象,大小不超过2M)Text('图片通知').onClick(()=>{let notificationRequest:notificationManager.NotificationRequest={id:5,content:{contentType:notificationManager.ContentType.NOTIFICATION_CONTENT_PICTURE,picture:{title:'图片通知标题',text:'图片通知内容',additionalText:'附加内容',expandedTitle:'展开图片标题',briefText:'text_picture',picture:this.imagePixelMap}}}notificationManager.publish(notificationRequest)})}.width('100%')}.height('100%')}
}

运行效果图:

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

相关文章:

  • 什么是网关鉴权及其在Spring Cloud Gateway中的实现
  • 【机器学习与实现】支持向量机SVM
  • 当代人工智能三教父——深度学习三巨头
  • Django项目从创建到开发以及数据库连接的主要步骤,精简实用
  • linux 命令 grep 排除 No such file or directory
  • Unity 滑动条(Slider)拖拽开始和结束、点击等事件的拓展功能
  • Linux 学习知识 (简单易懂 )持续更新 Linux输出重定向 Linux通配符 Linux正则表达式 持续更新....
  • 前端vue用el-table如何实现表头内容过长换行处理,实现换行效果
  • 15:00面试,15:08出来,面试问的有点变态。。。。
  • 【BUG】流式响应requests得到: ping - 和时间戳
  • 人工智能应用-实验5-BP 神经网络分类手写数据集
  • K8s Pod 资源进阶
  • 掌握Edge浏览器的使用技巧
  • Qt封装ping命令并将ping结果显示到界面
  • 图论(洛谷刷题)
  • 安卓部署ffmpeg全平台so并实现命令行调用
  • Go语言中MD5盐值加密解决用户密码问题
  • flutter开发实战-本地SQLite数据存储
  • 【路由組件】
  • 【C++风云录】数字逻辑设计优化:电子设计自动化与集成电路
  • Flask Response 对象
  • 算法001:移动零
  • 基于springboot+vue+Mysql的网上书城管理系统
  • python实现绘制烟花代码
  • Python小白的机器学习入门指南
  • 学校上课,是耽误我学习了。。
  • OpenFeign高级用法:缓存、QueryMap、MatrixVariable、CollectionFormat优雅地远程调用
  • python基础之函数
  • 深入理解C#中的IO操作 - FileStream流详解与示例
  • 信息泄露--注意点点