title: WebView Cache not working in Android 4.4
body: <p>I have been working on an application that caches an image from the web and shows it even when the user is offline. This worked pretty well until Android 4.4 came out. Now, all I see is a "Can not load the webpage" error. I suppose it might have to do something with the fact that Kitkat uses Chromium for loading webviews, but I am not very sure. Any fixes for this?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
  mWebView.setWebViewClient(new MyWebViewClient());
  
  mWebViewSettings = mWebView.getSettings();
  mWebViewSettings.setJavaScriptEnabled(true);
  mWebViewSettings.setAllowFileAccess(true);
  mWebViewSettings.setAppCacheEnabled(true);
  if (Build.VERSION.SDK_INT &lt; 18)
      mWebViewSettings.setAppCacheMaxSize(5 * 1024 * 1024); // 5MB
  mWebViewSettings.setLoadsImagesAutomatically(true);
  mWebViewSettings.setAppCachePath(getActivity().getApplicationContext()
          .getCacheDir().getAbsolutePath());
  mWebViewSettings.setBuiltInZoomControls(true);
  if(Build.VERSION.SDK_INT&lt;=18)
      mWebViewSettings.setDefaultZoom((WebSettings.ZoomDensity.FAR));
  mWebViewSettings.setUseWideViewPort(true);
  mWebViewSettings.setLoadWithOverviewMode(true);
  </code></pre>
  
  <p>I am loading it using the following code:</p>
  
  <pre><code>if (NetworkUtil.IS_ONLINE_WITH_DATA_CONNECTION) {
  
      MyPrefs = getActivity().getSharedPreferences(
              "AHSelectionPreffs",
                      Context.MODE_PRIVATE);
      Date CAMPUS_MAP_LAST_UPDATE_DATE = new Date();
      String CAMPUS_MAP_LAST_UPDATE_DATE_STRING = MyPrefs
                  .getString("CAMPUS_MAP" + String.valueOf(StorageHelper.ID), null);
  
      SimpleDateFormat simpleDateFormatter = new SimpleDateFormat(
                              "EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
  
      if (CAMPUS_MAP_LAST_UPDATE_DATE_STRING != null) {
          try {
              CAMPUS_MAP_LAST_UPDATE_DATE = simpleDateFormatter
                      .parse(CAMPUS_MAP_LAST_UPDATE_DATE_STRING);
  
          } catch (ParseException e1) {
  
              e1.printStackTrace();
              System.out.println("Cant format date!!!!");
          }
          int n = (int) ((curDate.getTime() - CAMPUS_MAP_LAST_UPDATE_DATE
                                  .getTime()) / (1000 * 60 * 60));
  
          if (n &lt; 24 * UPDATE_DURATION_IN_DAYS) {
              mWebView.getSettings().setCacheMode(
                                      WebSettings.LOAD_CACHE_ELSE_NETWORK);
  
          } else {
              updateCampusMapData();
  
          }
      } else {
  
          updateCampusMapData();
  
      }
  
  } else {
      mWebView.getSettings().setCacheMode(
                      WebSettings.LOAD_CACHE_ELSE_NETWORK);
  }
  
  if (StorageHelper.campus_map_link.Mobile_Link_URL != null) {
          mWebView.loadUrl(StorageHelper.campus_map_link.Mobile_Link_URL);
  
  }
  
  private void updateCampusMapData() {
      mWebView.getSettings().setCacheMode(
          WebSettings.LOAD_NO_CACHE);
      MyPrefs = getActivity().getSharedPreferences(
          "AHSelectionPreffs", Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = MyPrefs.edit();
      editor.putString("CAMPUS_MAP" + String.valueOf(StorageHelper.ID),
                          curDate.toString());
      editor.commit();
  
  }
  </code></pre>