Skip to content

x-startintent-s 打开协议链接

打开网页、自定义协议和应用链接。参数与回调对齐 DCloud plus.runtime.openURLsuccess / fail / complete

成功只表示已经交给系统处理,不代表目标应用一定完成业务。

兼容性

HarmonyiOSAndroidWEB微信小程序
支持支持支持支持仅 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:// 等必填
packageNameAndroid 指定包名,显式拉起某个应用
success成功,errMsgstartIntent:ok-
fail失败-
complete结束-

没有 scheme 的地址会自动补 https://

错误码

含义
1001系统错误,或正在打开其它链接
1002参数错误,链接为空或无法解析
1003无法打开,没有可处理的应用
1008当前平台不支持此功能

平台差异

  1. Android 使用 ACTION_VIEWintent://android-app://Intent.parseUri。Android 11+ 用 <queries> 声明常见协议,未声明的自定义协议 canOpenIntent 可能为 false,但仍可尝试 startIntent
  2. iOS 使用 UIApplication.open。自定义协议要写进 LSApplicationQueriesSchemes,否则 canOpenURL 会返回 false。
  3. HarmonyOS 先 openLink,失败再 startAbility + ohos.want.action.viewData
  4. Web 用 <a> 打开;自定义协议依赖浏览器和已安装应用。
  5. 微信小程序仅支持 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)

首次发布

最近更新