Android App Links 配置

App Links 是 Android 官方提供的一种"通用链接"机制, 让 HTTPS 链接可以直接唤起对应的 App,而不是跳转浏览器,类似于iOS的Universal Links。

平台 名称 配置文件 功能
iOS Universal Links apple-app-site-association (AASA) 点击网页 → 打开 App
Android Aoo Links assetlinks.json 点击网页 → 打开 App

例如: https://xxx.com/callback/123

  • 如果设备上安装了 App → 自动打开 App;
  • 如果没安装 → 打开网页(优雅降级)。

当用户点击链接时,系统会验证:

  1. 链接的域名(如 xxx.com)
  2. 对应域名下的 .well-known/assetlinks.json
  3. JSON 文件中是否声明了你的 App 包名 + 签名指纹

验证通过后,Android 会在系统中记录「此域名可由该 App 直接处理」。

三、配置步骤

1.在你的服务器添加assetlinks.json

在根目录下添加,路径为 .well-known/assetlinks.json

assetlinks.json 内容为:

json 复制代码
[
  {
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target": {
      "namespace": "android_app",
      "package_name": "your_package_name",
      "sha256_cert_fingerprints": [
        "xxxxxx"  // 签名
      ]
    }
  },
  ]

要求:

  • 必须是 HTTPS;
  • 不能重定向
  • header中必须是ontent-Type: application/json;
  • 文件路径必须是 .well-known/assetlinks.json

2.在 AndroidManifest.xml 中添加 <intent-filter>

找到你的主 Activity

xml 复制代码
<activity
    android:name=".ui.activity.MainActivity"
    android:exported="true"
    android:launchMode="singleTop"
    android:theme="@style/LaunchTheme">

    <!-- 普通启动 -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>

    <!-- App Links -->
    <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="xxx.com"
              android:pathPrefix="/callback"/>
    </intent-filter>

</activity>

说明:

  • android:autoVerify="true" 会让系统自动去验证 assetlinks.json;
  • android:host 必须和网站域名一致;
  • android:pathPrefix 指定可唤起的路径;
  • 可配置多个 <intent-filter> 来匹配不同路径。

更快捷的配置

Android studio 提供了更快捷的配置:Tools → App Links Assistant → Create AppLink; 一共有四部,按照流程即可配置完成。

相关推荐
parade岁月43 分钟前
VTable Guild 3.0.0 发布,面向 Vue 3 的 ProTable 式业务表格
前端
xurileidian1 小时前
第 17 篇 · 边玩边学Python · for 遍历 enumerate 与 zip
java·前端·python
掘金安东尼2 小时前
更多审查智能体,更少盲区:GitHub Copilot 代码审查是怎么做的
前端·github copilot
Hilaku4 小时前
2026 年了,jQuery 真的该死了吗?
前端·javascript·程序员
zach4 小时前
吃透 React setState 同步异步之谜:从批量更新、事件循环到版本演进的完整拆解
前端·react.js
不服老的小黑哥4 小时前
02-从 pnpm dev 到 Spring Boot 启动:后端服务到底怎么跑起来?
前端
htzyl2064 小时前
javaScript——this 的四种绑定:为什么箭头函数改不了它
前端·javascript
欧雷殿5 小时前
做自己的第一位客户:一人公司的数据治理公开实践
前端·ai编程·团队管理
掘金安东尼5 小时前
换上 Gemini 4 Neon 之后,我改了哪些上下文工程大模型
前端
涛涛ing6 小时前
我把项目里的 Zustand 全删了:代码量减半,Bug 少了,性能还起飞了
前端