如何在HarmonyOS鸿蒙Next中跳转到其他应用的指定页面

如何在HarmonyOS鸿蒙Next中跳转到其他应用的指定页面,目前通过startAbility的方式,有没有相关文档,是否支持类似deeplink这种方式跳转

5 回复

目前只能通过startability启动其他应用,want传参,其他应用再跳转到指定页面。
5.0会有appLinking机制

文档链接:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/inter-app-redirection-V5

更多关于如何在HarmonyOS鸿蒙Next中跳转到其他应用的指定页面的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,跳转到其他应用的指定页面可以通过Want对象实现。首先,定义Want对象,设置目标应用的bundleNameabilityName。然后,使用startAbility方法启动目标页面。例如:

let want = {
    bundleName: "com.example.targetapp",
    abilityName: "com.example.targetapp.MainAbility"
};
this.context.startAbility(want).then(() => {
    console.log("跳转成功");
}).catch((err) => {
    console.error("跳转失败", err);
});

确保目标应用已安装且页面可访问。

在HarmonyOS Next中,可以通过隐式Want跳转到其他应用的指定页面,这种方式类似于DeepLink。以下是实现方法:

  1. 配置目标应用的跳转能力: 在目标应用的module.json5中配置skills标签,声明支持的uri和页面路径:
"abilities": [
  {
    "name": "TargetAbility",
    "skills": [
      {
        "actions": ["action.system.detail"],
        "uris": [
          {
            "scheme": "harmony",
            "host": "targetapp",
            "path": "/detail"
          }
        ]
      }
    ]
  }
]
  1. 发起跳转的代码:
let wantInfo = {
  action: 'action.system.detail',
  uri: 'harmony://targetapp/detail?id=123'
};
try {
  await context.startAbility(wantInfo);
} catch (err) {
  console.error(`Failed to start ability. Code: ${err.code}, message: ${err.message}`);
}
  1. 目标应用接收参数处理: 在目标Ability的onCreate()中通过want.uri获取参数:
onCreate(want: Want) {
  let uri = want.uri; // 可解析uri中的参数
}

这种方式支持完整的URI跳转,包括scheme、host、path和query参数,与Android的DeepLink机制类似。注意目标应用需要提前安装,且双方应用需要声明相关权限。

回到顶部