简体   繁体   English

我们如何将同一提供商的子域添加到基于 TWA 的 android 应用程序?

[英]How can we please add subdomains from same provider to TWA based android app?

I am trying to add subdomain for a single TWA App.我正在尝试为单个 TWA 应用程序添加子域。 I have done the asset linking done from website to app.我已经完成了从网站到应用程序的资产链接。 I can see the URL bar every time even if the linking is done.即使链接完成,我每次都能看到 URL 栏。

strings.xml字符串.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 Android清单

 <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" />

//added intent filter in android manifest //在 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"/>

i can see the www.xxxx.com without a url bar but for www.abcd.xxxx.com i can see the URL bar.我可以看到没有 url 栏的 www.xxxx.com 但对于 www.abcd.xxxx.com 我可以看到 URL 栏。

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

i checked the linking using the below link and it returns that host has granted app deep linking我使用以下链接检查了链接,它返回主机已授予应用深度链接

I've been digging around to try and solve this myself, and while I don't have an answer just yet, I've made enough progress where I am able to change the subdomain from within my TWA and not have the url bar showing. 我一直在努力尝试自己解决此问题,尽管我还没有答案,但我已经取得了足够的进展,可以在TWA内更改子域,而没有显示网址栏。

My first step was to set my asset statements to have a wildcard: 我的第一步是将资产报表设置为具有通配符:

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

I was then able to set my android.support.customtabs.trusted.DEFAULT_URL meta-data to any URL on my subdomain and it worked happily with my current assetlinks.json file located on my web-server. 然后,我能够将android.support.customtabs.trusted.DEFAULT_URL元数据设置为子域上的任何URL,并且它可以与位于Web服务器上的当前assetasses.json文件一起愉快地工作。 However I could not change my subdomain/url from within the app, as this would open the URL bar. 但是,我无法在应用程序中更改子域/ URL,因为这会打开URL栏。

As I was testing I started trying out different URL's (our web-app has many sub-domains) and I noticed that previously tested domains started to work. 在进行测试时,我开始尝试使用不同的URL(我们的Web应用程序具有许多子域),并且我注意到先前测试的域开始起作用。 It seems that by setting URL's as DEFAULT_URL the app is somehow caching these as trusted. 似乎通过将URL设置为DEFAULT_URL ,应用程序以某种方式将它们缓存为受信任的。 I have tried uninstalling the app and clearing my Chrome cache and this persists, so I'm not sure how this is working. 我尝试卸载应用程序并清除我的Chrome缓存,但是这种情况仍然存在,因此我不确定这是如何工作的。

Something I can definitely confirm for you is that setting: 我可以肯定地为您确认的是该设置:

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

Will not work, you are trying to set metadata on a class name, and when I explore the android.support.customtabs.trusted class I can see that DEFAULT_URL is the only property that is used for URL definition. 将无法正常工作,您正在尝试在类名称上设置元数据,并且当我探索android.support.customtabs.trusted类时,我可以看到DEFAULT_URL是唯一用于URL定义的属性。

My conclusions so far: I dont believe you need multiple asset_statements. 到目前为止,我的结论是:我认为您不需要多个asset_statement。 I don't believe you need multiple meta-data fields and I don't believe setting multiple data:host fields in the intent-filter is having the desired effect. 我不认为您需要多个元数据字段,也不相信在intent-filter中设置多个data:host字段会达到预期的效果。 The bottom line I think is currently there's no supported way to handle subdomains in a TWA. 我认为最重要的是,目前尚没有支持在TWA中处理子域的方法。

EDIT: 编辑:

Just confirmed that this magical caching of trusted URL's is happening as I test and install different versions of the app. 刚刚确认,当我测试并安装该应用程序的不同版本时,这种对可信URL的神奇缓存正在发生。 Installing the latest version on another device reverts back to a single trusted URL and the sub-domain navigation is failing. 在另一台设备上安装最新版本将还原为单个受信任的URL,并且子域导航失败。

you should add the assetlinks.json file to every subdomain your app might visit to 您应该将assetlinks.json文件添加到您的应用可能访问的每个子域中

so all these links should return the asset file 因此所有这些链接应返回资产文件

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

also make sure it follows these guidelines . 还要确保它遵循这些准则

200 response and content-type application/json redirects will not work 200个响应和内容类型的application/json重定向将不起作用

In order to get read of the status bar, you need to check these two steps:为了读取状态栏,您需要检查以下两个步骤:

  1. you should add /.well-known/assetlinks.json endpoint for each of the subdomains.您应该为每个子域添加/.well-known/assetlinks.json端点。 See the link for the reference: https://developer.android.com/training/app-links/verify-site-associations#publish-json请参阅参考链接: https : //developer.android.com/training/app-links/verify-site-associations#publish-json

  2. In the android manifest you should add the intent filter with the wildcard for the host value.在 android 清单中,您应该添加带有主机值通配符的意图过滤器。 Note: the host value should strictly start with the * and do not contain a schema, like https://注意:主机值应严格以 * 开头,并且不包含架构,例如 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>

You don't have to explicitly specify all subdomains in asset_statments .您不必在asset_statments明确指定所有子域。 It's enough to have your default one there.在那里有你的默认值就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让我的 Android 应用程序始终在 Chrome 或其他支持 TWA 的浏览器中打开? - How can I get my Android app to always open in Chrome or another browser that supports TWA? 从 TWA 将 android 应用设备令牌发送到 WordPress web - Send android app device token to WordPress web from a TWA 如何使用 TWA 全屏制作 Android 应用程序(沉浸式) - How to make Android app using TWA full screen (immersive) 如何注销用户,当 android twa 应用程序最小化或发送到后台时 - How to logout user, when android twa app is minimized or sent to background 如何通过应用内审查扩展 TWA 应用程序? - How can I extend TWA application with In-App review? 我们如何在 Android 上添加应用小部件作为高级功能选项 - How can we add app widgets as a premium feature option on Android 如何将数据从我的 TWA 网络应用程序发送到我的应用程序? - How to send data from my TWA webapp to my app? 有没有一种方法可以根据对 Outlook Android 应用程序的某些验证显示 Outlook 添加通知 - Is there a way we can display Outlook Add In Notification based on certain validation on an Outlook Android App 我们可以在一个应用程序中实现多少内容提供商? - How many content provider we can implement in one app? 如何在 TWA 和 FCM 之间添加集成? - How to add integration between TWA and FCM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM