Cordova web browser crop in android

I am trying to clear the cache stored in an Android application that uses cordova webview. I tried using cordovaWebView.clearCache(true); Also tried using

 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; } 

But both did not work. Can I get any solution for this, since the user can log into the system in a web browser and, therefore, we need to clear the cache when loading the application a second time.

+2
source share
3 answers

I use the plug-in "cordova-plug-cache-clear"

https://github.com/anrip/cordova-plugin-cache-clear

To use the plugin, just call window.CacheClear(success, error);

and it clears the webView cache.

+1
source

Why don't you use the org.felixtioh.phonegap.plugins.cachecleaner plugin

http://plugreg.com/plugin/sagittaros/CacheCleaner

It worked for me.

0
source

The simplest answer to this question is:

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

cordovaWebView is an example of Cordovawebview.

Use both when you need to clear cookies and cache.

0
source

Source: https://habr.com/ru/post/1233961/


All Articles