HarmonyOS鸿蒙Next中如何在华为浏览器中点击链接跳转我开发的App呢?
HarmonyOS鸿蒙Next中如何在华为浏览器中点击链接跳转我开发的App呢? 如题,官方文档有介绍使用AppLinking跳转到别的应用,但是如何在网页中点击后跳转到自己的应用呢?
【背景知识】 Deep Linking:采用Deep Linking进行跳转时,系统会根据接口中传入的uri信息,在本地已安装的应用中寻找到符合条件的应用并进行拉起。
【参考方案】: 可参考H5通过url scheme拉起应用示例,基于Deep Linking实现H5拉起应用时检测是否可以打开相关应用,已安装则拉起,未安装则打开应用市场进行下载。
- 在拉起方的module.json5文件中配置querySchemes字段,表示本应用可能会用到的scheme查询。
"module": {
"querySchemes": [
"hwtips",
],
}
- 在被拉起方的module.json文件中的skill字段中配置该应用支持的scheme协议,表示这个应用可以通过此协议打开,例如玩机技巧应用想被成功拉起则需要玩机技巧应用在工程的model.json5文件中配置abilities的skills中配置。
"skills": [
{
"actions": [
"ohos.want.action.viewData"
],
"uris": [
{
"scheme": "hwtips"
}
]
}
]
- 使用onLoadIntercept拦截前端请求,目的是获取拉起应用的url。
Web({ src: $rawfile('PullUp.html'), controller: this.controller })
.onLoadIntercept((event) => {
if (event) {
let url: string = event.data.getRequestUrl();
}
})
- 使用canOpenLink检测是否可以打开相关应用,可以打开则拉起应用。
if (canOpen) {
const WANT: Want = {
uri: url
}
const CONTEXT= getContext(this) as common.UIAbilityContext;
CONTEXT.startAbility(WANT).then(() => {
// 拉起成功
}).catch(() => {
})
}
- 若未安装,不可打开则跳转应用市场进行下载。
if (canOpen) {
} else {
promptAction.showDialog({
title: $r('app.string.tips'),
message: $r('app.string.download'),
buttons: [{
text: $r('app.string.confirm'),
color: $r('app.string.fontcolor'),
}]
});
.then(index => {
const WANT: Want = {
uri: `store://appgallery.huawei.com/app/detail?id=com.huawei.hmos.tips`
}
const CONTEXT = getContext(this) as common.UIAbilityContext;
CONTEXT.startAbility(WANT).then(() => {
})
})
}
更多关于HarmonyOS鸿蒙Next中如何在华为浏览器中点击链接跳转我开发的App呢?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
好的,谢谢,
以下是鸿蒙(HarmonyOS)官方提供的 App Linking 相关参考文档和开发者指南地址,供你查阅和集成使
-
App Linking 官方开发指南 文档地址 https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V5/app-linking-introduction-0000001473220905-V5
-
App Linking API 参考(ArkTS)
好的,
- 楼上提到的Applinking
- 补充一个简单的临时方案,把App的应用市场链接直接写入,但这样需要用户再点击一次“打开”才会跳转到应用。
请参考APPLinking相关开发文档: AppLinking开发指南
除了参考链接以外,注意事项:
1、需要手动签名
2、需要在自己的服务器和AppGellary中进行正确配置
3、除了基本配置外,还要注意冷启动和热启动问题
以上也是基于本人开发经验的内容和提示
好的,谢谢,
通过华为浏览器点击链接跳转到自己的应用,核心是通过 AppLinking 实现深度链接
按照文档配置好云恻端
客户端在 module.json5 中声明关联域名与路径:
{
"module": {
"abilities": [
{
"skills": [
{
"actions": ["ohos.want.action.viewData"],
"uris": [
{
"scheme": "https",
"host": "www.example.com",
"path": "app/link", // 前后不要加斜杠
"pathRegex": ".*" // 支持正则匹配
}
]
}
]
}
]
}
}
构造标准的 HTTPS 链接格式,例如:
https://www.example.com/app/link?param1=value1¶m2=value2
在 HTML 页面中通过以下方式触发:
<a href="https://www.example.com/app/link?param1=value1">跳转到鸿蒙应用</a>
好的,
在HarmonyOS Next中,通过Deep Link实现跳转。首先在App的config.json中声明uri权限,添加intent-filter配置目标链接格式。然后在华为浏览器中,符合该格式的链接会触发系统弹窗,用户确认后即可跳转到App。
在HarmonyOS Next中,可以通过AppLinking实现从华为浏览器跳转到你的应用。具体步骤如下:
- 配置AppLinking:在AppGallery Connect中为你的应用创建AppLinking链接,并关联对应的页面路径。
- 处理Deep Link:在应用的
module.json5
文件中声明对应的URI Scheme,例如:"abilities": [ { "uri": "example://detail" } ]
- 网页中嵌入链接:在网页中放置AppLinking格式的链接,例如:
<a href="https://example.applinking.huawei.com/xxx">打开应用</a>
- 应用内处理跳转:在应用的UIAbility中通过
onCreate
或onNewWant
方法解析URI参数并导航到对应页面。
注意确保华为浏览器支持AppLinking跳转,且用户已安装你的应用。