【问题标题】:Is it possible to have multiple main domains (hostName) in a TWA?TWA 中是否可以有多个主域(主机名)?
【发布时间】:2021-01-20 13:52:18
【问题描述】:

我有一个提供多种语言的网站,每种语言都链接到一个域(.com、.co.uk、.de 等),我正在为它做一个带有 Bubblewrap 的 TWA。

我已将 .com 设置为 TWA 的主要主机名,并且我已授权其他域,如官方文档中所述。 (https://developers.google.com/web/android/trusted-web-activity/multi-origin)。

它运作良好,我可以毫无问题地在 TWA 中切换域(使用语言切换器),如果我点击谷歌搜索结果或电子邮件中的 .com 链接,那么它在TWA。

但是,如果我点击 .co.uk 链接,它会在网络浏览器中打开,而我希望它也能在 TWA 中打开。

是否可以允许多个主要“主机名”,或允许在 TWA 中自动识别和打开多个域?

【问题讨论】:

    标签: trusted-web-activity twa bubblewrap


    【解决方案1】:

    是的,您需要将额外的域添加到AndroidManifest.xml 中的intent-filter

    使用twa-multi-domain 示例,应用程序中的主域是www.google.comgithub.comwww.wikipedia.com 是额外域。添加 2 个额外的域后,AndroidManifest.xml 部分应如下所示(第 13 到 16 行是新的):

                ...
                <activity android:name="com.google.androidbrowserhelper.trusted.LauncherActivity"
                android:label="@string/app_name">
    
                ...
    
                <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="www.google.com"/>
                    <data android:scheme="https"
                        android:host="github.com"/>
                    <data android:scheme="https"
                        android:host="www.wikipedia.com"/>
                </intent-filter>
            </activity>
            ...
    

    【讨论】:

    • 它就像一个魅力,非常感谢@andreban!我还有一个问题:是否可以记住上次打开的域,并带有 AndroidManifest.xml 中的参数?使用您的示例:我第一次打开应用程序(因此它将打开 www.google.com)我转到另一个授权域(github.com)现在,如果我关闭 TWA,我希望它打开现在在 github.com
    • 记住用于打开 TWA 的最后一个域是可能的 - 您需要实现自己的 LauncherActivity,扩展原始 LauncherActivity 并添加您自己的 getLaunchingUrl() 实现。但是,如果 TWA 启动域 A 并且用户在 TWA 内导航到域 B,它将无法记住最后一个域。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 1970-01-01
    • 2022-10-01
    • 1970-01-01
    • 2012-09-02
    • 1970-01-01
    • 2021-07-13
    相关资源
    最近更新 更多