存储WebView以进行脱机浏览

时间:2021-06-13 20:09:30

What would be the best way to force Android to store a webview to a media once the page is loaded?

加载页面后,强制Android将webview存储到媒体的最佳方法是什么?

A few more details:

更多细节:

  • Each page will be rich with images, scripts and styling.

    每个页面都将丰富的图像,脚本和样式。

  • Each page will be about 0.5 to 1 Megabyte.

    每页大约0.5到1兆字节。

  • They will be saved once the OnFinishedLoading Override is called.

    一旦调用OnFinishedLoading Override,它们将被保存。

  • It would be best to save it to the SD Card then use the local repo to open it back up.

    最好将其保存到SD卡,然后使用本地仓库将其打开备份。

Not sure if I should just use a sql database for the webviews, or take each view and do a write out to a file.

不确定我是否应该只为webview使用sql数据库,或者采用每个视图并写出文件。

If I do the latter, what would be the easiest way so I don't have to write a full webcrawler to get each file linked?

如果我做后者,那么最简单的方法是什么,所以我不必写一个完整的webcrawler来连接每个文件?

1 个解决方案

#1


7  

In order to use caching on Android, you need to provide an HTML5 manifest file along with your HTML.

要在Android上使用缓存,您需要提供HTML5清单文件以及HTML。

<!DOCTYPE html>
<html lang="en" manifest="manifest.file">
<head> ...

The caching mechanism will cache whatever entries you will list in the manifest file into an SQLite database. Keep in mind that the database is per app, not per webview. (I had a lot of problems with this).

缓存机制会将清单文件中列出的任何条目缓存到SQLite数据库中。请记住,数据库是每个应用程序,而不是每个webview。 (我有很多问题)。

This article explains all the steps you need to take to achieve this. http://web.archive.org/web/20140314001433/http://alex.tapmania.org/2010/11/html5-cache-android-webview.html

本文介绍了实现此目的所需的所有步骤。 http://web.archive.org/web/20140314001433/http://alex.tapmania.org/2010/11/html5-cache-android-webview.html

You can do a hello-world example for caching using this page: http://html5demos.com/offlineapp

您可以使用此页面进行缓存的hello-world示例:http://html5demos.com/offlineapp

You can save the cache on the SD card, as long as you add the WRITE_EXTERNAL_STORAGE permission to the application manifest.

只要将WRITE_EXTERNAL_STORAGE权限添加到应用程序清单,就可以将缓存保存在SD卡上。

Good luck!

祝你好运!

#1


7  

In order to use caching on Android, you need to provide an HTML5 manifest file along with your HTML.

要在Android上使用缓存,您需要提供HTML5清单文件以及HTML。

<!DOCTYPE html>
<html lang="en" manifest="manifest.file">
<head> ...

The caching mechanism will cache whatever entries you will list in the manifest file into an SQLite database. Keep in mind that the database is per app, not per webview. (I had a lot of problems with this).

缓存机制会将清单文件中列出的任何条目缓存到SQLite数据库中。请记住,数据库是每个应用程序,而不是每个webview。 (我有很多问题)。

This article explains all the steps you need to take to achieve this. http://web.archive.org/web/20140314001433/http://alex.tapmania.org/2010/11/html5-cache-android-webview.html

本文介绍了实现此目的所需的所有步骤。 http://web.archive.org/web/20140314001433/http://alex.tapmania.org/2010/11/html5-cache-android-webview.html

You can do a hello-world example for caching using this page: http://html5demos.com/offlineapp

您可以使用此页面进行缓存的hello-world示例:http://html5demos.com/offlineapp

You can save the cache on the SD card, as long as you add the WRITE_EXTERNAL_STORAGE permission to the application manifest.

只要将WRITE_EXTERNAL_STORAGE权限添加到应用程序清单,就可以将缓存保存在SD卡上。

Good luck!

祝你好运!