Is there a way to pre-cache a web page for viewing with an Android WebView?

前端 未结 1 1958
难免孤独
难免孤独 2021-02-15 18:48

I\'ve read about the HTML5 cache manifest, and I\'ve seen Android does support caching websites using the cache manifest. I want to use the cache manifest to download all the re

相关标签:
1条回答
  • 2021-02-15 19:32

    What you want to do requires implementing a mechanism for app cache, linked resources, cookies, and local database store for HTML5 apps that use database API, and that's an important part of what browsers do in these days. I don't recommend doing the caching by yourself, not only because it's so much work, but also because I can't recall any method in WebView and it's friends (WebViewClient, etc.) that accepts an outside cache.

    But your problem has a very simpler solution: you can put a WebView in your view and set its visibility to gone. Then make it visible when it has finished loading the page. WebView also automatically keeps the cache for your app so that the next time it runs it loads the page more quickly.

    For hiding your WebView and then automatically showing it you just have to override onPageFinished in WebViewClient.

    0 讨论(0)
提交回复
热议问题