
回复
openLink
或startAbility
接口startAbility
结合类型匹配config.json
中声明支持的URL规则:
"skills": [
{
"request": {
"uri": {
"scheme": "myapp",
"host": "shop",
"path": "/location"
}
}
}
]
myapp://shop/location?address=xxx
scheme/host/path
找到对应应用特性 | Deep Linking | App Linking |
---|---|---|
协议 | 自定义scheme | 标准https |
域名校验 | 无 | 强制校验域名合法性 |
未安装处理 | 返回错误码 | 跳转浏览器打开链接 |
安全性 | 较低 | 较高(HTTPS加密) |
import { common } from '@ohos.app.ability.common';
// 拉起地图显示指定坐标
context.openLink('geo:39.9042,116.4074'); // 北京天安门坐标
const want: common.Want = {
action: 'ohos.want.action.sendToData',
uri: 'mailto:support@harmony.com?subject=反馈&body=问题描述',
flags: 3 // 读写权限标志
};
context.startAbility(want);
// 接收方处理URI参数
onCreate(want) {
const uri = want.uri;
if (uri) {
const path = url.URL.parseURL(uri).path;
if (path === '/product/123') {
loadProductDetail(123);
}
}
}
`common.getAbilityInfo({ bundleName: 'com.map.app' })`
HarmonyOS的应用跳转机制通过精准匹配与安全校验,实现了跨应用的无缝协作。开发者可根据场景选择Deep Linking或App Linking,结合openLink/startAbility
接口,为用户打造流畅的多应用交互体验。