x-startintent-s 打开协议链接
打开网页、自定义协议和应用链接。参数与回调对齐 DCloud plus.runtime.openURL 的 success / fail / complete。
成功只表示已经交给系统处理,不代表目标应用一定完成业务。
兼容性
| Harmony | iOS | Android | WEB | 微信小程序 |
|---|---|---|---|---|
| 支持 | 支持 | 支持 | 支持 | 仅 http/https |
调用
ts
import { startIntent, XStartIntentOptions } from "@/uni_modules/x-startintent-s"
startIntent({
url: "https://www.dcloud.io",
success: (res) => {
console.log(res.errMsg, res.url)
},
fail: (err) => {
console.log(err.errCode, err.errMsg)
}
} as XStartIntentOptions)检测是否可打开:
ts
import { canOpenIntent, XCanOpenIntentOptions } from "@/uni_modules/x-startintent-s"
canOpenIntent({
url: "weixin://",
success: (res) => {
console.log(res.canOpen)
}
} as XCanOpenIntentOptions)方法
| 名称 | 说明 |
|---|---|
| startIntent | 打开协议链接或应用 |
| canOpenIntent | 检测当前设备是否能处理该协议 |
参数
XStartIntentOptions
| 字段 | 说明 | 默认 |
|---|---|---|
| url | 要打开的链接。支持 http(s)、tel、mailto、sms、geo、weixin://、alipays://、intent:// 等 | 必填 |
| packageName | Android 指定包名,显式拉起某个应用 | 空 |
| success | 成功,errMsg 为 startIntent:ok | - |
| fail | 失败 | - |
| complete | 结束 | - |
没有 scheme 的地址会自动补 https://。
错误码
| 码 | 含义 |
|---|---|
| 1001 | 系统错误,或正在打开其它链接 |
| 1002 | 参数错误,链接为空或无法解析 |
| 1003 | 无法打开,没有可处理的应用 |
| 1008 | 当前平台不支持此功能 |
平台差异
- Android 使用
ACTION_VIEW;intent://、android-app://走Intent.parseUri。Android 11+ 用<queries>声明常见协议,未声明的自定义协议canOpenIntent可能为 false,但仍可尝试startIntent。 - iOS 使用
UIApplication.open。自定义协议要写进LSApplicationQueriesSchemes,否则canOpenURL会返回 false。 - HarmonyOS 先
openLink,失败再startAbility+ohos.want.action.viewData。 - Web 用
<a>打开;自定义协议依赖浏览器和已安装应用。 - 微信小程序仅支持 http/https,走
wx.openUrl,需要对应权限。
版本
版权归 https://xui.tmui.design 你不得修改及二次开发,仅供 TMUI4 会员商用使用。不得转给非 VIP 会员使用,一经查实数倍赔偿,并追究法律责任。
更新日志
1.1.0(2026-08-20)
- 改为 DCloud success / fail / complete 风格
- 新增 startIntent、canOpenIntent,移除旧方法 openWeb
- 支持自定义协议、Android intent://,去掉鸿蒙远程 HAR 依赖
1.0.3(2025-07-25)
- 兼容原生鸿蒙
1.0.2(2025-03-15)
- 兼容ios16+
1.0.1(2025-02-10)
- 兼容微信
1.0.0(2024-08-24)
首次发布
