Saving WebView page to cache

后端 未结 2 736
旧巷少年郎
旧巷少年郎 2021-01-05 20:31

I have an app with WebView and I want the app to save the website the first time it is connected to the internet so that a further connection is no longer needed. I know som

2条回答
  •  醉话见心
    2021-01-05 20:49

    You can directly use the WebView cache.

    Typically, this is activated with the WebSettings.setCacheMode, using the mode LOAD_CACHE_ELSE_NETWORK

    Use cached resources when they are available, even if they have expired.

    Use like so :

    webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    

    However, in your case, the page declares a 'no-cache' option, which may prevent the WebView to store the page in cache altogether.

    If you have the hand on the server side, you can also use the Application Caches API (see http://www.html5rocks.com/en/tutorials/appcache/beginner/ for more details on how that works)

提交回复
热议问题