如何使用 OpenLink 跳转深度链接?

【如何通过 URL Scheme 打开应用指定页面?】

可以通过在 iOS 或 Android 系统中使用特定的 URL Scheme 来打开应用并跳转到指定页面。以下是具体实现方式:

iOS 平台

  1. 配置 URL Scheme

    • 在 Xcode 项目中,进入 TargetInfoURL Types
    • 添加一个新的 URL Type,设置 URL Schemes 为自定义的标识,例如:myapp
  2. 在 AppDelegate 中处理 URL

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        // 解析 URL 并跳转到对应页面
        if let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
           let scheme = components.scheme,
           scheme == "myapp" {
            // 根据 path 或 query 参数决定跳转逻辑
            if let path = components.path, path == "/profile" {
                // 跳转到个人中心页面
                // 例如:self.navigateToProfile()
            }
        }
        return true
    }
    
  3. 调用方式

    • 在 Safari 浏览器或其它应用中输入:myapp://profile
    • 系统会尝试打开对应应用,并触发上述方法。

Android 平台

  1. 在 AndroidManifest.xml 中配置 Activity 的 Intent Filter

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="myapp" android:host="profile" />
        </intent-filter>
    </activity>
    
  2. 在 Activity 中解析 Intent

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        Intent intent = getIntent();
        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            Uri data = intent.getData();
            if (data != null && "myapp".equals(data.getScheme())) {
                String host = data.getHost();
                if ("profile".equals(host)) {
                    // 跳转到个人中心页面
                    // 例如:navigateToProfile();
                }
            }
        }
    }
    
  3. 调用方式

    • 在浏览器或其它应用中输入:myapp://profile
    • 系统会启动对应应用并传递参数。

注意事项

  • URL Scheme 必须唯一,避免与其他应用冲突。
  • iOS 需要用户手动授权,部分系统版本可能限制非标准 Scheme。
  • 建议配合 Universal Links(iOS)App Links(Android) 实现更安全、可靠的跳转机制。
  • 可通过 query parameters 传递额外参数,如:myapp://profile?id=123&name=John
HarmonyOS
2026-06-17 09:40:46
浏览
收藏 0
回答 1
已解决
回答 1
按赞同
/
按时间
WebWarden

【调用方:

await getContext().openLink('harmonyos://com.example.app/detail?id=123')

被调用方 module.json5

"skills": [
  {
    "actions": ["ohos.want.action.viewData"],
    "uris": [
      {
        "scheme": "harmonyos",
        "host": "com.example.app",
        "path": "/detail"
      }
    ]
  }
]

接收方在 onNewWant 中解析 URI 参数跳转对应页面。openLink 找不到匹配应用时抛出异常,需 try-catch。】

分享
微博
QQ
微信
回复
2026-06-17 11:29:04
相关问题
如何用AppLinking实现深度链接跳转
61浏览 • 1回复 待解决
如何实现 OpenLink 跳转
55浏览 • 1回复 已解决
如何实现 AppLinking 深度链接
382浏览 • 1回复 已解决
应用链接深度链接(App Linking)
365浏览 • 1回复 已解决
如何使用@ObservedV2和@Trace深度观测
54浏览 • 1回复 待解决
如何OpenLink打开其他应用?
64浏览 • 1回复 已解决
使用ArkUI和ArkTS如何运行深度学习模型
3903浏览 • 1回复 待解决
HarmonyOS 跳转到外部浏览器固定链接
1444浏览 • 1回复 待解决
如何优化布局避免深度嵌套?
89浏览 • 1回复 已解决
鸿蒙如何与 DeepSeek 深度融合?
1227浏览 • 1回复 已解决
HarmonyOS UIAbilityContext.openLink 为 undefined
1263浏览 • 1回复 待解决