手机短信可以唤醒APP吗?


猪小花1号提问于 2018-08-28 16:06
1 个回答
  • 达芬奇密码2018-08-28 16:09

    通常,App 监听私有短域名strange.com(不要问我为什么是短域名,因为短信就是按字算钱的,能省一分是一分)地址:

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

    1、Android 系统

    当点击短信中的链接后,系统会自行判断,如果安装了 App 就会出一个弹框让用户选择在 App 中打开还是在浏览器中打开,如图。

    <figure>对用户来说要多做一次选择,这绝对不是好的体验。

    为了解决这个问题,Android 6.0 开始支持 Deep Links,让用户点击链接直达 App。

    首先,在 intent-filter 中添加 android:autoVerify="true"

    <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="strange.com"
            android:scheme="https"/>
    </intent-filter>
    

    其次,在私有域下上传一个 json 文件: https://strange.com/.well-known/assetlinks.json

    文件内容:

    [
        {
            "relation": ["delegate_permission/common.handle_all_urls"],
            "target": {
                "namespace": "android_app",
                "package_name": "应用ID",
                "sha256_cert_fingerprints":["签名证书指纹"]
            }
        }
    ]
    

    系统在安装应用后会自动访问 json 文件进行检验,如果检验通过,用户访问 strange.com 域名下的链接会直接跳转到应用。

    2、iOS 系统

    必须采用 Universal Links,否则点击还是直接跳转到浏览器。

    从短信直接唤起 App 总结:

    要实现短信直接唤起 App,Android 可以用 intent-filter 对域名进行监听,但是会出弹框让用户进行选择,为了更好的体验,建议采用 Deep Links 技术方案,只支持 6.0 以上系统;iOS 只能采用 Universal Links 技术方案,只支持 9.0 以上系统。

    系统 首选方案 备选方案

    Android DeepLinks(Android 6.0+) intent-filter

    iOS UniversalLinks(iOS 9.0+) 无,只能跳浏览器


    以上答案来自我厂黄仕彪老师的博文《一切为了运营!如何从推广短信链接唤起 App? 》。