【问题标题】:How to implement app links on android marshmallow?如何在 android marshmallow 上实现应用链接?
【发布时间】:2015-10-01 17:15:50
【问题描述】:

Android 6.0 中正在更改应用链接,以便 Android 更清楚哪些应用可以直接打开内容,而不是每次都通过对话框阻止用户。

如何实现?

【问题讨论】:

    标签: android android-6.0-marshmallow applinks


    【解决方案1】:

    是的,App Links 是 Android Marshmallow 6.0 上的新功能和很酷的功能。这让您可以通过 aster 方式打开您拥有的域的网站链接。

    applink需要满足两个条件:

    1. 为网址添加<intent-filter>
    2. 验证域的所有权

    确保您至少有 1 个带有意图过滤器的 Activity。

    <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.domain.com"/>
            <data android:scheme="https" android:host="www.domain.com" />
        </intent-filter>
    </activity>
    
    应用链接的

    意图过滤器必须声明 android:schemehttphttps 或两者。过滤器不得声明任何其他方案。过滤器还必须包含 android.intent.action.VIEWandroid.intent.category.BROWSABLE 类别名称。

    别忘了在上面添加android:autoVerify="true" 属性 &lt;intent-filter&gt; 这将告诉系统启动域 在设备上安装应用时进行验证。

    现在要将您的网站与您的应用相关联,您需要在您的网站上添加数字资产链接 JSON 文件。和你网站根目录下的路径一模一样

    https://www.domain.com/.well-known/assetlinks.json
    

    以下示例assetlinks.json 文件授予链接打开权限 给com.example Android app

    这是 JSON 文件的样子:

    [{
      "relation": ["delegate_permission/common.handle_all_urls"],
      "target": {
        "namespace": "android_app",
        "package_name": "com.example",
        "sha256_cert_fingerprints":
        ["14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"]
      }
    }]
    

    只需替换值"package_name":"sha256_cert_fingerprints": 让其他人保持原样。

    确保您创建的文件可通过HTTPS 协议访问

    现在您可以测试应用程序了,您可以按照android developer documentation 博客的说明进行测试

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多