title: Android WebView isn't loading cached Website if there is no connection
body: <p>I am trying to cache the website loaded in WebView but I can't get it working if the network connection is OFF.</p>
  <p>Cachdirectory is created, cached files are there. Permissions are given. I load the WebPage then switch off network (WI-FI permission is also given) and I get the error as I am trying to reload the page (now it should load from cache). Plase help!</p>
  <p>Here is the code:</p>
  <pre><code>WebView engine=(WebView)findViewById(R.id.web_engine);
      engine.getSettings().setJavaScriptEnabled(true);
      engine.getSettings().setBuiltInZoomControls(true);
      engine.getSettings().setLoadsImagesAutomatically(true);
      engine.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
      engine.setInitialScale(1);
  
      engine.setWebViewClient(new WebViewClient());
      
      engine.setWebChromeClient(new WebChromeClient() 
      {
            @Override
               public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota,QuotaUpdater quotaUpdater)
               {
                     quotaUpdater.updateQuota(spaceNeeded * 2);
               }
            public void onProgressChanged(WebView view, int progress)
            {
                activity.setTitle(&quot;Loading...&quot;);
                activity.setProgress(progress * 100);
  
                if(progress == 100)
                { 
                    activity.setTitle(R.string.app_name);
                }
            }
         });
      
      String appCachePath;
      
      engine.getSettings().setDomStorageEnabled(true);
     // Set cache size to 8 mb by default. should be more than enough
      engine.getSettings().setAppCacheMaxSize(1024*1024*8);
      appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
      engine.getSettings().setAppCachePath(appCachePath);
      engine.getSettings().setAllowFileAccess(true);
      engine.getSettings().setAppCacheEnabled(true);
      engine.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
  
       cm = (ConnectivityManager) this.getSystemService(Activity.CONNECTIVITY_SERVICE);
       if(cm.getActiveNetworkInfo() == null || !cm.getActiveNetworkInfo().isConnected())
       {           
           appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
           engine.getSettings().setAppCachePath(appCachePath);
           
           engine.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
           engine.loadUrl(&quot;http://www.google.com&quot;);
       }
       else
       {
           System.err.println(&quot;CACHE OR NETWROK&quot;);
           engine.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
           engine.loadUrl(&quot;http://www.google.com&quot;);
       }
  }
  </code></pre>
  <p>And Permissions:</p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot; /&gt;
  </code></pre>