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

标签 android chrome-custom-tabs

我正在寻找一种方法,正如标题所说,隐藏网址栏。

到目前为止我已经知道了,但它没有任何改变。

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

我曾尝试使用 webviews,但在文件上传和某些不能正常工作的 css 方面我遇到了无穷无尽的问题。自定义选项卡在所有这些方面都表现出色,而且速度似乎更快。

根据@113408 的回答,我正在尝试实现 TWA,我已经开始工作,添加了网站和应用程序之间的链接以及应用程序到网站的链接,但 URL 栏仍然可用。

这是 list 文件,因为它是我完成的唯一编码。

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

这是我的属性(property)证明

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

最佳答案

您可以使用 Trusted Web Activities 获得所需的结果

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.

最终,TWA 将允许您执行与 CustomChromeTabs 完全相同的操作,但会提供更多功能。

您要查找的更具体是 Remove the URL bar

Trusted Web Activities require an association between the Android application and the website to be established to remove the URL bar.

注意:隐藏 URL 栏时,请确保您通过 HTTPS 提供您的页面,否则您将无法隐藏,因为该页面被认为不安全

How to get HTTPS working on your local development environment in 5 minutes

关于android - 是否可以在 Chrome 自定义选项卡上隐藏 URL 栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54648249/

相关文章:

chrome-custom-tabs - 我想通过 chrome 自定义选项卡加载本地 html 文件,这可行吗?

Android Chrome 自定义标签回退

android - 三星Touchwiz始终在Android 4.1.1中启动时提示默认应用程序

android Thumbnails.getThumbnail() 和没有外部存储的手机

Android - 管理布局景观

android - 是否可以将 Chrome 自定义标签作为 View 对象

android - fragment 的 View 层次结构

java - 从 ArrayList 中删除随机项

android - 在 Chrome 自定义选项卡中检测到内存泄漏

android-intent - Android API 30 getPackageManager.resolveActivity() 使用 ACTION_VIEW 返回 null