简体   繁体   English

在 MAUI 的 Chrome 自定义选项卡中隐藏位置栏

[英]Hide the location bar in Chrome Custom Tabs in MAUI

So that I don't ask the wrong question, my end goal is to build a PWA that is accessible from Android 5.x and up now and iOS later in the year.所以我不会问错问题,我的最终目标是构建一个可从 Android 5.x 及更高版本以及今年晚些时候的 iOS 访问的 PWA。 The main problem with this is Classic Bluetooth is not yet stable/standardized enough for the web.主要问题是经典蓝牙对于网络来说还不够稳定/标准化。

My next plan was to build a "native" app (in .NET MAUI so that I can reuse parts in iOS) using a WebView for displaying the PWA and calling back to the native app for Bluetooth.我的下一个计划是构建一个“原生”应用程序(在 .NET MAUI 中,以便我可以在 iOS 中重用部分),使用 WebView 来显示 PWA 并回调原生应用程序以进行蓝牙。 The problem here is the WebView version on the devices I have to support doesn't support PWAs, service workers, etc. (upgrading the hundred or so hardware devices is not possible, upgrading the OS is not possible, and it's pre-Android-8 so upgrading WebView is not possible without a new ROM).这里的问题是我要支持的设备上的WebView版本不支持PWA、service worker等(升级一百多台硬件设备是不可能的,升级操作系统是不可能的,而且是pre-Android- 8 因此,如果没有新的 ROM,就无法升级 WebView)。

Finally I've tried installing Chrome via device management and using " Chrome Custom Tabs " from MAUI.最后,我尝试通过设备管理安装 Chrome 并使用 MAUI 中的“ Chrome 自定义选项卡”。 The simplest implementation works:最简单的实现工作:

// Browser is <IBrowser>Microsoft.Maui.ApplicationModel.Browser.Default
await Browser.OpenAsync(
    "https://www.whatismybrowser.com/detect/what-is-my-user-agent/",
    BrowserLaunchMode.SystemPreferred);

and the tab is displayed "in" my app, however the location bar is shown within the tab:并且标签显示在我的应用程序“中”,但是位置栏显示在标签内: 在 Chrome 自定义选项卡中显示位置栏的 Android 屏幕截图

Which brings me to the question:这让我想到了这个问题:

How do I use a Chrome Custom Tab from MAUI but hide the location bar?如何使用 MAUI 中的 Chrome 自定义选项卡但隐藏地址栏? Is this even possible?这甚至可能吗?

There's little to no documentation on this for MAUI.几乎没有关于 MAUI 的文档。 I've tried looking through the MAUI source, but all I can see are some options:我尝试过查看 MAUI 源代码,但我只能看到一些选项:

await Browser.OpenAsync("https://www.whatismybrowser.com/detect/what-is-my-user-agent/", new BrowserLaunchOptions
{
    LaunchMode = BrowserLaunchMode.SystemPreferred, // open inside the MAUI app, i.e. Custom Tab
    TitleMode = BrowserTitleMode.Hide, // doesn't seem to have any effect
    Flags = BrowserLaunchFlags.LaunchAdjacent // the only Android flag
});

The LaunchAdjacent flag just opens "up" instead of sideways. LaunchAdjacent 标志只是“向上”打开而不是侧向打开。 The other flags are for iOS, detailed here .其他标志适用于 iOS, 详见此处 The TitleMode doesn't seem to do anything. TitleMode 似乎没有做任何事情。

Reading about Chrome Custom Tabs here , it appears it's not possible, unless I own the destination URL and setup aTrusted Web Activity .在此处阅读有关 Chrome 自定义选项卡的信息,这似乎是不可能的,除非我拥有目标 URL 并设置了受信任的 Web 活动 Hosting a web app combined with a native app for Bluetooth may be the only way to go if I can't use a WebView.如果我不能使用 WebView,那么托管一个 Web 应用程序与蓝牙的本机应用程序可能是唯一的方法。

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

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