简体   繁体   English

是否可以在 Chrome 自定义选项卡上隐藏 URL 栏

[英]Is it possible to hide URL bar on Chrome Custom Tabs

I'm looking for a way to, as the title says hide the url bar.正如标题所说,我正在寻找一种方法来隐藏网址栏。

I've got this so far but it hasn't changed anything.到目前为止,我已经得到了这个,但它没有改变任何东西。

CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        builder.setShowTitle(false);
        builder.enableUrlBarHiding();
        CustomTabsIntent customTabsIntent = builder.build();
        customTabsIntent.launchUrl(this, Uri.parse(url));

I've tried to use webviews but I've had endless problems with them with regards to file upload and certain css that isn't working well.我尝试使用 webviews,但在文件上传和某些无法正常工作的 css 方面,我遇到了无穷无尽的问题。 The Custom Tab works well in all those aspects, and it seems faster.自定义选项卡在所有这些方面都运行良好,而且看起来更快。

As per @113408 answer I'm trying to implement a TWA, I've got it working, added the link between the website and the app and the app to the website, but the URL bar is still viable.根据@113408 的回答,我正在尝试实施 TWA,我已经让它工作,将网站和应用程序之间的链接以及应用程序添加到网站,但 URL 栏仍然可行。

Here is the manifest file as it is the only coding I've done.这是清单文件,因为它是我完成的唯一编码。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.app.comppanynme.twatest">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >

        <meta-data
            android:name="asset_statements"
            android:resource="@string/asset_statements" />

        <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="http://192.168.8.46" />

            <!-- This intent-filter adds the TWA to the Android Launcher -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <!--
              This intent-filter allows the TWA to handle Intents to open
              airhorner.com.
            -->
            <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="http"
                    android:host="192.168.8.46"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

Here is my asset statement这是我的资产声明

<string name="asset_statements">
        [{
            \"relation\": [\"delegate_permission/common.handle_all_urls\"],
            \"target\": {
                \"namespace\": \"web\",
                \"site\": \"http://192.168.8.46"}
        }]
    </string>

You can achieve the desired result using Trusted Web Activities您可以使用受信任的 Web 活动实现所需的结果

Trusted Web Activities are a new way to integrate your web-app content such as your PWA with your Android app using a protocol based on Custom Tabs.受信任的 Web 活动是一种使用基于自定义选项卡的协议将您的 Web 应用程序内容(例如 PWA)与您的 Android 应用程序集成的新方法。

Ultimately TWA will allow you to do exactly the same as the CustomChromeTabs but offer more functionalities.最终,TWA 将允许您执行与CustomChromeTabs完全相同的操作,但提供更多功能。

What you're looking for more specifically is Remove the URL bar您正在寻找更具体的是删除 URL 栏

Trusted Web Activities require an association between the Android application and the website to be established to remove the URL bar.受信任的 Web 活动需要在 Android 应用程序和要建立的网站之间建立关联以删除 URL 栏。

NB: When hiding the URL bar make sure you serve your page through HTTPS otherwise you will not be able to hide as the page is considered not secure .注意:隐藏 URL 栏时,请确保您通过HTTPS提供您的页面,否则您将无法隐藏,因为该页面被认为是不安全的。

How to get HTTPS working on your local development environment in 5 minutes 如何在 5 分钟内让 HTTPS 在本地开发环境中运行

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM