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

鸿蒙桌面快捷方式开发

桌面快捷方式开发实战

[参考文档] (https://developer.huawei.com/consumer/cn/doc/best-practices/bpta-desktop-shortcuts)

在module.json5配置文件中的abilities标签下的metadata中设置resource属性值为$profile:shortcuts_config,指定应用的快捷方式配置文件,即使用shortcuts_config.json文件中的shortcuts配置。

{"module": {// ..."abilities": [{"name": "EntryAbility","srcEntry": "./ets/entryability/EntryAbility.ets",// ..."skills": [{"entities": ["entity.system.home"],"actions": ["ohos.want.action.home"]}],"metadata": [{"name": "ohos.ability.shortcuts", // 配置快捷方式,该值固定为ohos.ability.shortcuts"resource": "$profile:shortcuts_config" // 指定shortcuts信息的资源位置}]}]}
}

shortcuts_config.json文件

{"shortcuts": [{"shortcutId": "shortcutId1","label": "$string:label1","icon": "$media:icon1","wants": [{"bundleName": "com.xxx.xxxx","moduleName": "entry","abilityName": "EntryAbility","parameters": {"shortcutsNamePath": "parameters"}}]}]
}

在EntryAbility.ets接受参数

  onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {if(want.parameters?.shortcutsNamePath){AppStorage.setOrCreate('shortcutsNamePath', want.parameters.shortcutsNamePath||'')}
...onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {if(want.parameters?.shortcutsNamePath){AppStorage.setOrCreate('shortcutsNamePath', want.parameters.shortcutsNamePath||'')}

使用HMRouter或者Navigation渲染完毕后恢复页面

  onPageShow(): void {// 根据存入的AppStorage书写恢复逻辑restoreThePageShortcut()}

恢复页面-快捷方式大概逻辑

export const restoreThePageShortcut = () => {const shortcutsNamePath = AppStorage.get('shortcutsNamePath') as string// 根据参数判断
if(shortcutsNamePath){
setTimeout(() => {
// 看情况处理AppStorage.setOrCreate('shortcutsNamePath', '') // 用完销毁})
}}

注意,关于图片,最好使用1024*1024图片,中间的图标较小的

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

http://www.xdnf.cn/news/9090.html

相关文章:

  • 进程通信(管道,共享内存实现)
  • 【unity游戏开发——编辑器扩展】Gizmos可视化辅助工具
  • Leetcode 1924. 安装栅栏 II
  • RabbitMQ 集群与高可用方案设计(二)
  • PyTorch实战(7)——生成对抗网络(Generative Adversarial Network, GAN)实践详解
  • 黑龙江云前沿-服务器托管
  • CentOS7安装 htop(100% 可以安上)
  • 使用VuePress开发日志
  • Redis与Lua脚本深度解析:原理、应用与最佳实践
  • ES文件管理器 安卓APP(文件管理器) v4.4.3.0 无广告高级版
  • 【无标题】第一章 Hello World的诅咒
  • 古腾堡编辑器教程:如何使用WordPress图库区块
  • 第十讲 | 继承
  • 商品颜色/尺码选项太多谷歌爬虫不收录怎么办?
  • 自动化测试:等待方式
  • 体育数据支撑比分网的全链路技术解析:从架构设计到场景落地
  • SQLMesh 用户定义变量详解:从全局到局部的全方位配置指南
  • OpenSSL 文件验签与字符串验签原理及 C 语言实现详解
  • 编程中优秀大模型推荐:特点与应用场景深度分析
  • Pycharm的简单介绍
  • 002大模型-提示词工程,少样本提示,角色扮演,思维链
  • 基于python+Django+Mysql的校园二手交易市场
  • 在 Windows 上使用 WSL 安装 Ansible详细步骤
  • x86 与 ARM 汇编深度对比:聚焦 x86 汇编的独特魅力
  • 利用python爬虫获取淘宝天猫商品评论封装API实战演示
  • 【生物信息学】k-mer的基本概念及应用
  • python打卡day37@浙大疏锦行
  • tc3975开发板上有ft2232这块的电路,我想知道这个开发板有哪些升级方式,重点关注是怎样通过ft2232实现的烧录升级的
  • 单片机上按键功能通常都是用什么方法写?
  • 《DeepSeek行业应用全景指南(视频微课版)》:从入门到精通的AI落地实践手册