我试图清除存储在使用cordova webview的android应用程序中的缓存.
我试过cordovaWebView.clearCache(true);也尝试过
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视图中用户使用登录,因此我们需要在第二次加载应用程序时清除缓存.
解决方法:
我正在使用“cordova-plugin-cache-clear”插件
https://github.com/anrip/cordova-plugin-cache-clear
要使用该插件,只需调用window.CacheClear(success,error);
它清理webView缓存.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。