Android WebView not loading second page from cache

后端 未结 5 1368

I have an Android app that simply houses a website. I would like the app to cache the pages of the website for offline use.

I\'m doing a simple test to see if the cache

5条回答
  •  别跟我提以往
    2021-02-05 21:19

    This is not the exact answer to your question, as you are asking about webview cache. But, it can achieve the same result.

    // saving page from web to file 
    File file = new File(this.getExternalFilesDir(null), "fileName.html");
    FileUtils.copyURLToFile(new URL("http://www.bmimobile.co.uk/why-bmi.php"), file);
    
    
    // loading saved file in webview
    webview.loadUrl("file://" + file.getPath());
    

    This is a more flexible approach, as you have control over loading, saving, and much more.

提交回复
热议问题