鸿蒙Next开发中如何配置AppLink扫码直达功能
在鸿蒙Next开发中,如何配置AppLink实现扫码直达功能?具体需要哪些步骤?是否需要额外声明权限或配置特定的元数据?希望能提供详细的代码示例和注意事项。
2 回复
在鸿蒙Next中配置AppLink扫码直达,只需三步:
- 在
module.json5中声明skills,添加entities和actions。 - 配置
continuable为true,支持扫码拉起。 - 测试时用DevEco生成二维码,手机一扫,App秒开!
简单说:配好技能,开continuable,扫码起飞!🚀
更多关于鸿蒙Next开发中如何配置AppLink扫码直达功能的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在鸿蒙Next中配置AppLink扫码直达功能,可通过以下步骤实现:
1. 配置AppLink信息
在 module.json5 文件中添加 abilities 和 skills 配置,声明AppLink的URI Scheme和Action:
{
"module": {
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ets",
"skills": [
{
"entities": ["entity.system.home"],
"actions": ["action.system.view"],
"uris": [
{
"scheme": "demo",
"host": "example.com",
"port": "8080",
"path": "detail"
}
]
}
]
}
]
}
}
2. 处理AppLink数据
在Ability的 onCreate 或 onNewWant 生命周期中解析URI参数:
import UIAbility from '@ohos.app.ability.UIAbility';
import Want from '@ohos.app.ability.Want';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
// 从want中获取AppLink的URI
let uri = want.uri;
if (uri) {
// 解析URI中的参数,例如:demo://example.com:8080/detail?id=123
console.info('AppLink URI: ' + uri);
// 执行页面跳转或业务逻辑
}
}
}
3. 生成二维码
使用第三方库(如QRCode.js)生成包含AppLink URI的二维码:
// 示例URI:demo://example.com:8080/detail?id=123
const appLink = 'demo://example.com:8080/detail?id=123';
4. 扫码测试
- 使用系统相机或扫码工具扫描二维码。
- 设备会自动识别URI Scheme并触发应用拉起。
注意事项:
- 域名验证:生产环境需配置关联域名(在AGC控制台配置Digital Asset Links)。
- 路径匹配:确保扫码内容与
uris配置的scheme、host、path完全匹配。 - 权限声明:若使用网络权限,需在
module.json5中声明ohos.permission.INTERNET。
通过以上配置,即可实现鸿蒙Next的AppLink扫码直达功能。

