App Links的使用以及坑

本文详细介绍AppLinks在Android6.0及以上版本的应用配置方法,包括如何设置intent-filter实现从URL直接启动应用,以及创建assetlinks.json文件进行域名绑定验证的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

App Links可以从一个URL或者短信中直接启动APP。不过只能在Android 6.0的版本上才能使用。

配置

在想调用的Activity上加上

<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="http" android:host="www.example.com" />
        <data android:scheme="https" />
    </intent-filter>

但是如果是在启动页,不要将启动页的intent-filter和这个一起写,要分开。比如

  <activity
            android:name=".LaunchActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <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:host="xxx.com"
                    android:pathPrefix="/xxx"
                    android:scheme="https"/>
            </intent-filter>
        </activity>

android:host可以填写:baidu.com
android:pathPrefix是匹配的路径,比如baidu.com/download,这里android:pathPrefix就填:/download
这里需要注意的是,不要在baidu.com的域名加上www.,我在小米手机上试了,是无法启动APP的。比如你的网址是www.baidu.com,那么android:host=“baidu.com”。切记切记切记。我在调试的时候就是因为这个无法启动APP。

在网站上创建assetlinks.json文件

文件名一定要是assetlinks.json。不要更改。

文件的内容

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "你的包名",
    "sha256_cert_fingerprints":
    ["证书指纹SHA256的值"]
  }
}]

获取SHA256的值
输入adb的命令:keytool -list -v -keystore “填写jks的路径”
输入后会输入密码,然后就找证书指纹SHA256的值。
记得给服务器的证书指纹SHA256要和你运行的APP一致。有人就有可能用了正式的签名,却用了debug的包。
然后将该文件放在网站的.well-known目录下,放了之后要试试能不能用:

https://domain.name/.well-known/assetlinks.json

测试是否绑定成功

在Android studio上命令行输入:

adb shell dumpsys package domain-preferred-apps

如果存在绑定的会显示如下结果:

Package: com.android.vending
Domains: play.google.com market.android.com
Status: always : 200000002

Status: always是代表绑定了,但是Status: undefined或者Status: ask都是没有绑定成功。如果Status: ask时,检查一下host是否加了www.。如果加了就要去掉。

优点:

  • 如果APP安装的话,不会弹选择框,直接启动APP
  • 可以直接通过url跳到对应的activity

缺点:

  • 需要Android 6.0以上
  • 网站需要支持https
  • 有个校验过程,步骤麻烦些。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猿界新星蔡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值