1

我正在尝试为单个 TWA 应用程序添加子域。我已经完成了从网站到应用程序的资产链接。即使链接完成,我每次都能看到 URL 栏。

字符串.xml

<resources>
<string name="app_name">XXXX </string>
    <string name="asset_statements" translatable="false">
    [{
        \"relation\": [\"delegate_permission/common.handle_all_urls\"],
        \"target\": {
            \"namespace\": \"web\",
            \"site\": \"https://www.xxxx.com\"}
    },{
        \"relation\": [\"delegate_permission/common.handle_all_urls\"],
        \"target\": {
            \"namespace\": \"web\",
            \"site\": \"https://www.abcd.xxxx.com\"}
    }]

</string>
</resources>

AndroidManifest

 <activity
        android:name="android.support.customtabs.trusted.LauncherActivity">

        <!-- Edit android:value to change the url opened by the TWA -->
        <meta-data
            android:name="android.support.customtabs.trusted.DEFAULT_URL"
            android:value="https://www.xxxx.com" />
        <meta-data
            android:name="android.support.customtabs.trusted"
            android:value="https://www.abcd.xxxx.com" />

//在android清单中添加意图过滤器

 <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE"/>

            <!-- Edit android:host to handle links to the target URL-->
            <data
                android:scheme="https"
                android:host="www.xxxx.com"/>
            <data
                android:scheme="https"
                android:host="www.abcd.xxxx.com"/>

我可以看到没有网址栏的 www.xxxx.com,但对于 www.abcd.xxxx.com,我可以看到网址栏。

https://developers.google.com/digital-asset-links/tools/generator

我使用以下链接检查了链接,它返回该主机已授予应用程序深度链接

4

3 回答 3

0

我一直在努力尝试自己解决这个问题,虽然我还没有答案,但我已经取得了足够的进展,我可以从我的 TWA 中更改子域并且没有显示 url 栏.

我的第一步是将我的资产声明设置为具有通配符:

    <string name="asset_statements">
        [{
            \"relation\": [\"delegate_permission/common.handle_all_urls\"],
            \"target\": {
                \"namespace\": \"android_app\",
                \"site\": \"https://*.newvote.org\"}
        }]
    </string>

然后,我能够将我的android.support.customtabs.trusted.DEFAULT_URL元数据设置为我的子域上的任何 URL,并且它与我当前位于我的网络服务器上的 assetslinks.json 文件一起工作得很好。但是我无法从应用程序中更改我的子域/url,因为这会打开 URL 栏。

在测试时,我开始尝试不同的 URL(我们的网络应用程序有许多子域),我注意到以前测试过的域开始工作。似乎通过将 URL 设置为DEFAULT_URL应用程序以某种方式将这些缓存为受信任。我已尝试卸载该应用程序并清除我的 Chrome 缓存,但这种情况仍然存在,所以我不确定它是如何工作的。

我可以肯定地为您确认的是该设置:

<meta-data android:name="android.support.customtabs.trusted" android:value="@string/app_url" />

不起作用,您正在尝试在类名上设置元数据,当我探索android.support.customtabs.trusted该类时,我可以看到这DEFAULT_URL是用于 URL 定义的唯一属性。

到目前为止我的结论:我不相信你需要多个资产声明。我不相信您需要多个元数据字段,并且我不相信在意图过滤器中设置多个数据:主机字段会产生预期的效果。我认为的底线是目前没有支持的方式来处理 TWA 中的子域。

编辑:

刚刚确认,当我测试和安装不同版本的应用程序时,这种可信 URL 的神奇缓存正在发生。在另一台设备上安装最新版本会恢复为单个受信任的 URL,并且子域导航失败。

于 2019-07-30T04:32:22.007 回答
0

您应该将assetlinks.json 文件添加到您的应用程序可能访问的每个子域中

所以所有这些链接都应该返回资产文件

  https://www.xxxx.com/.well-known/assetlinks.json
  https://www.abcd.xxxx.com/.well-known/assetlinks.json

还要确保它遵循这些准则

200 响应和内容类型application/json 重定向将不起作用

于 2019-08-14T20:53:02.400 回答
0

为了读取状态栏,您需要检查以下两个步骤:

  1. 您应该/.well-known/assetlinks.json为每个子域添加端点。请参阅链接以获取参考:https ://developer.android.com/training/app-links/verify-site-associations#publish-json

  2. 在 android 清单中,您应该为主机值添加带有通配符的意图过滤器。注意:主机值应严格以 * 开头,并且不包含架构,例如 https://

    <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="*.xxxx.com"/>
    </intent-filter>
    

您不必在asset_statments. 在那里有你的默认值就足够了。

于 2021-11-03T11:17:44.737 回答