2014-11-05 125 views
2

我想清除存儲在使用科爾多瓦webview的android應用程序中的緩存。 我試着用cordovaWebView.clearCache(true);還與科爾多瓦網絡視圖緩存清除在Android中

public void deleteCache(Context context) { 
     Log.i("Utility", "deleting Cache"); 
     try { 
      File dir = context.getCacheDir(); 
      if (dir != null && dir.isDirectory()) { 
       deleteDir(dir); 
      } 
     } catch (Exception e) { 
      Log.e("Utility", " exception in deleting cookies"); 
     } 

    } 


public static boolean deleteDir(File dir) { 
     if (dir != null && dir.isDirectory()) { 
      String[] children = dir.list(); 
      for (int i = 0; i < children.length; i++) { 
       boolean success = deleteDir(new File(dir, children[i])); 
       if (!success) { 
        return false; 
       } 
      } 
     } else if (dir != null && dir.isFile()) { 
      dir.delete(); // delete the file INSIDE the directory 
     } 
     Log.i("Utility", "deleting Cache " + dir.delete()); 
     return true; 
    } 

但都沒有工作嘗試。 我可以得到任何解決方案,因爲在Web視圖用戶使用登錄,因此我們需要清除緩存時第二次加載應用程序。

回答

0

最簡單的答案,這是

cordovaWebView.clearCache(true); 
android.webkit.CookieManager.getInstance().removeAllCookie(); 

cordovaWebView是Cordovawebview的實例。

在需要清除cookie和緩存的情況下使用兩者。