0

I want to setAppCachePath() path to check later which urls are cached & which are not before loading them. If there is no internet and the url is not cached I want to skip loading it.

 File dir = new File(Environment.getExternalStorageDirectory().getPath()+"/Android/data/" +
 if (!dir.exists()) {
            dir.mkdirs();
     }
        Log.i("cache",dir.getPath());

  wv.getSettings().setAppCachePath(dir.getPath());         

But, the cache folder is created & remains empty all the time .I think webview is caching the urls on its default location only. How can this be solved

I tried http://www.devahead.com/blog/2012/01/saving-the-android-webview-cache-on-the-sd-card/ solution but this is also not working

I have gone through to : Check if url is cached webview android

WebView Cache Data Directory?

Saving External Cache Files

How to move webView cache to SD?

Check if file already exists in webview cache android

Community
  • 1
  • 1
Rachita Nanda
  • 4,509
  • 9
  • 42
  • 66

1 Answers1

0

It is just a work around if that method is not working.

Here is a possible solution:

WebView webview = new WebView(context);
webview.setWebViewClient(new WebViewClient(){

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
         makeGetRequestAndCacheResult(String url);
         return false;
    }
});
hoomi
  • 1,882
  • 2
  • 16
  • 17