HarmonyOS 鸿蒙Next中添加桌面快捷方式(非卡片形式)
HarmonyOS 鸿蒙Next中添加桌面快捷方式(非卡片形式) 昨天看到微信的功能,可以把微信小程序添加到桌面,现在想问问鸿蒙现在有没有对应的功能
2 回复
在鸿蒙Next中创建桌面快捷方式:
- 使用ShortcutManager API添加静态快捷方式
- 动态快捷方式通过ShortcutInfo.Builder构建
- 必须声明ohos.permission.SET_SHORTCUT权限
- 示例代码:
ShortcutInfo shortcut = new ShortcutInfo.Builder(context, "id") .setLabel("快捷方式") .setIcon(icon) .setIntent(intent) .build(); ShortcutManager manager = context.getShortcutManager(); manager.addShortcut(shortcut);
更多关于HarmonyOS 鸿蒙Next中添加桌面快捷方式(非卡片形式)的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
HarmonyOS Next确实支持添加桌面快捷方式(非卡片形式),目前主要有两种实现方式:
- 对于小程序:
- 开发者可以通过在manifest.json中配置"shortcut"字段来声明快捷方式
- 用户可以在应用内长按功能入口,选择"添加到桌面"
- 对于原生应用:
- 使用ShortcutManager API创建静态或动态快捷方式
- 静态快捷方式在manifest中配置
- 动态快捷方式可在运行时通过代码添加
注意:需要申请ohos.permission.INSTALL_SHORTCUT权限。具体实现可参考官方文档中关于ShortcutManager的说明。
快捷方式会以应用图标的形式出现在桌面,点击后直接跳转到指定功能页面。