安卓系统使用uni-app app link启动app后拿不到链接地址
安卓系统使用uni-app app link启动app后拿不到链接地址
| 产品分类 | uniapp/App |
|---|---|
| PC开发环境操作系统 | Windows |
| PC开发环境操作系统版本号 | 10 |
| HBuilderX类型 | 正式 |
| HBuilderX版本号 | 4.87 |
| 手机系统 | Android |
| 手机系统版本号 | Android 16 |
| 手机厂商 | 华为 |
| 手机机型 | mate30 |
| 页面类型 | vue |
| vue版本 | vue2 |
| 打包方式 | 云端 |
| 项目创建方式 | HBuilderX |
操作步骤
在google play console的深层链接页面,点击已配置好的深层链接,在弹出的模拟器中测试当前链接,能启动APP,但在onShow方法里获取不到已配置的path: /en/detail/1360359.html;
预期结果
能正常获取配置的地址path: /en/detail/1360359.html
实际结果
plus.runtime.arguments是空值,options.path的值是首页地址
bug描述
安卓系统的深层链接APP link,配置好AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="com.xxx.app">
<application>
<!--meta-data-->
<activity android:name="io.dcloud.PandoraEntry" android:exported="true">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"
android:host="www.xxx.com"
android:path="/en/detail/1360359.html" />
</intent-filter>
</activity>
</application>
</manifest>
app.vue
onShow: function(options) {
const args = plus.runtime.arguments
const path = options.path
uni.showToast({
icon: 'none',
title: `${args} path:$path}`,
duration: 10000,
})
}
更多关于安卓系统使用uni-app app link启动app后拿不到链接地址的实战教程也可以访问 https://www.itying.com/category-93-b0.html
在onShow方法里使用延迟获取参数也是空值,官方有什么解决方案吗
更多关于安卓系统使用uni-app app link启动app后拿不到链接地址的实战教程也可以访问 https://www.itying.com/category-93-b0.html
该问题请在专业群( uni-app 官方技术交流群 1 ) 咨询,群中有相关专业的管理员和群友。
问题定位 您遇到的是 Android App Link 启动后无法获取链接地址 的问题,核心原因是 AndroidManifest.xml 中的 intent-filter 配置过于严格,导致只能匹配固定路径 /en/detail/1360359.html,而实际测试时可能访问的是动态路径(如 /en/detail/123456.html),因此系统未将链接传递给应用。
解决方案
-
修正 AndroidManifest.xml 配置 将固定路径改为动态匹配规则,支持所有 /en/detail/*.html 格式的链接:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="www.xxx.com" android:pathPattern="/en/detail/.*\\.html" />
</intent-filter> -
获取链接地址的代码调整 在 App.vue 的 onShow 生命周期中,通过 plus.runtime.arguments 获取完整 URL(需确保使用 自定义基座或正式包 测试):
onShow: function(options) {
// 获取完整链接(如 https://www.xxx.com/en/detail/1360359.html)
const url = plus.runtime.arguments;
if (url) {
// 解析路径和参数
const path = new URL(url).pathname; // 输出 “/en/detail/1360359.html”
const id = path.match(//detail/(\d+).html/)[1]; // 提取 “1360359”uni.showToast({ icon: 'none', title: `完整链接: ${url}\n提取ID: ${id}`, duration: 5000 });}
} -
验证步骤
重新打包:使用 HBuilderX 的 自定义调试基座 或 云端打包 生成新 APK。
测试链接:通过 Google Play Console 模拟器或浏览器访问 https://www.xxx.com/en/detail/1360359.html,确认应用启动后能正确解析路径。
注意事项
动态路径匹配:若路径规则更复杂(如 /en/detail/123/456.html),可改用 android:pathPrefix="/en/detail" 匹配所有子路径。
HarmonyOS 差异:HarmonyOS 的 Deep Link 需通过 module.json5 配置,参数获取方式不同(参考 鸿蒙文档)。
按上述步骤调整后,问题应可解决。如仍异常,请提供复现 APK 和测试链接,我们将进一步排查。 内容为 AI 生成,仅供参考
plus.runtime.arguments在Android App Link启动场景下为空,且options.path为首页地址,说明深层链接的intent数据未被正确解析到uni-app层。
原因分析:
- domain验证未通过(最常见):App Link要求服务器根目录或
.well-known/assetlinks.json文件必须正确配置且被Google索引,否则Android会降级为普通深层链接(需用户选择应用),且plus.runtime.arguments可能无法获取。 android:path精确匹配限制:您在AndroidManifest.xml中使用android:path="/en/detail/1360359.html",若实际链接包含查询参数(如?utm_source=xx)或路径末尾有斜杠,则匹配失败,导致intent不被该activity接收。应改用android:pathPrefix="/en/detail/"或android:pathPattern。- 启动模式影响:若App已处于前台,点击链接只会触发
onShow,但初始intent数据在主进程初始化时已消耗,plus.runtime.arguments需在onLaunch中获取,且onShow的options.path是uni-app路由路径而非原生intent路径。 - 模拟器局限性:Google Play Console的模拟器可能未触发完整的App Link验证流程,建议使用真实设备通过adb命令测试:
adb shell am start -a android.intent.action.VIEW -d "https://www.xxx.com/en/detail/1360359.html"


