安卓中清除 Cordova Web 视图缓存

3

我正在尝试清除使用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视图中,用户使用登录,因此当第二次加载应用程序时,我们需要清除缓存。

2个回答

2

0

最简单的答案是

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

cordovaWebView 是 CordovaWebview 的实例。

在需要清除 cookie 和缓存的情况下同时使用它们。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接