存储WebView以进行脱机浏览 [英] Storing a WebView for offline browsing

查看:134
本文介绍了存储WebView以进行脱机浏览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



更多细节:


  • 每个页面都会很丰富包括图片,脚本和样式。


  • 每个页面大约0.5到1兆字节。一旦OnFinishedLoading Override被调用,它们将被保存。


  • 最好将它保存到SD卡,然后使用本地回购打开它会备份。


    不知道我是否应该为webviews使用sql数据库,或者将每个视图和写一个文件。



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

    解决方案

    为了在Android上使用缓存,您需要提供一个HTML5清单文件和HTML。

     <!DOCTYPE html> 
    < html lang =enmanifest =manifest.file>
    < head> ...

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

    本文解释了您需要采取的所有步骤来实现此目标。 http ://web.archive.org/web/20140314001433/http://alex.tapmania.org/2010/11/html5-cache-android-webview.html



    您可以使用此页面为缓存做一个hello-world示例:
    http:// html5demos。 com / offlineapp



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

    祝你好运!

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

    A few more details:

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

    • Each page will be about 0.5 to 1 Megabyte.

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

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

    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.

    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?

    解决方案

    In order to use caching on Android, you need to provide an HTML5 manifest file along with your 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).

    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

    You can do a hello-world example for caching using this page: 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.

    Good luck!

    这篇关于存储WebView以进行脱机浏览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆