webview - 如何在Google Chrome(而不是WebView)中从Google Play打开PWA?

标签 webview google-play android-webview apk progressive-web-apps

我为网站的每个子域都有一个自定义的PWA。想法是在Google Play上安装一个PWA,当安装该PWA时,用户可以选择一个子域,将其重定向到该子域,然后提示他安装与所选子域相关的PWA。

问题是从Google Play(或直接从apk)安装的PWA在WebView中打开,这似乎不会在子域上触发berforeinstallprompt事件(当我在Google Chrome中打开子域时,该事件被正确触发)。 WebView菜单中的“添加到主屏幕”选项仍然可用。

这给了我两个选择,但是我无法让它们中的任何一个起作用:

1)在Google Chrome(而不是WebWiev)中运行从Google Play安装的PWA。

2)了解如何在WebView中触发berforeinstallprompt

有可能吗?怎么样?

捕获berforeinstallprompt事件并显示安装按钮的代码与https://developers.google.com/web/fundamentals/app-install-banners/上的代码非常相似,因此问题应该出在其他地方。

    var deferredPrompt;
    var button = document.getElementById("install-button");

    window.addEventListener('beforeinstallprompt', (e) => {
        e.preventDefault();
        deferredPrompt = e;
        button.style.display = 'block';
    });

最佳答案

仅在某些情况下会触发beforeinstallprompt,例如,如果您的应用程序已经安装,或者您的网站未满足https中的所有请求。另外,尝试运行lighthouse more tools => developer tools => Audits并运行,看看您的应用程序是否已优化。

请描述更多您想要实现的目标,为什么要在PWA中使用子域?

关于webview - 如何在Google Chrome(而不是WebView)中从Google Play打开PWA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56277486/

相关文章:

android - Web View 在滚动时闪烁/闪烁

javascript - 如何在 android webview 中使用 js 获取特定的 <div >'s data by it' s id?

java - 无法在使用名称或包名称搜索时找到上传的应用程序

ionic-framework - 从商店取消发布应用之前的“待办事项”列表

android - 以前工作时,上传 Unity Android App Bundle 导致 Google Play 64 位不合规错误

java - 互联网连接异常失败

android - youtube 视频不在 iframe 的 android webview 中播放

重启activity后Android WebView白页

javascript - android webview wrapp 内容不起作用,webview 在加载页面后无法设置高度

android - 替换安卓默认的webview