【问题标题】:Is it possible to download the entire react app and then load it on to the webview?是否可以下载整个 react 应用程序,然后将其加载到 webview 中?
【发布时间】:2021-10-04 18:53:36
【问题描述】:

我创建了一个 android 应用程序,将 react 应用程序加载到 webview 上。但是,react 应用程序有一些页面上有视频。这里的问题是这个应用程序应该在最初设置应用程序后几乎没有或根本没有互联网的情况下工作(这意味着当应用程序第一次启动时会有良好的互联网连接)。我想知道是否有办法下载整个 webapp,将其保存在设备上的某个位置,然后使用 webview 从那里加载它,而不是从外部 URL 加载。 此外,如果有更好的方法来解决这个问题,任何帮助将不胜感激。 到目前为止,我已经尝试缓存 webview,但性能几乎没有提高。

【问题讨论】:

    标签: android reactjs android-studio caching webview


    【解决方案1】:

    编写一个原生加载器应用。让它下载所有文件。确保文件都使用彼此的相对引用。然后下载后,将其加载到 webview 中。可能最简单的方法是将它们全部压缩到 1 个文件中,然后下载 zip 并将其解压缩到本地存储。

    如果您也将文件包含在加载程序中,您可以使用代码:

    if (has internet) 
      save to disk from internet //Can use cache headers to see if there's an update and if not skip the download
    if (!has on disk)
      copy files from APK to disk
    load from disk
    

    这样,即使您第一次没有互联网连接,它也能正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-30
      • 1970-01-01
      • 2021-02-22
      相关资源
      最近更新 更多