clear WebView Cache - Android User Interface

Android examples for User Interface:WebView

Description

clear WebView Cache

Demo Code


//package com.java2s;

import android.content.Context;

import java.io.File;

public class Main {
    private static final String APP_CACAHE_DIRNAME = "/webcache";

    static public void clearWebViewCache(Context context) {

        try {/*from  ww w  . j  a  va2s  .c  o m*/
            context.deleteDatabase("webview.db");
            context.deleteDatabase("webviewCache.db");
        } catch (Exception e) {
            e.printStackTrace();
        }

        File appCacheDir = new File(context.getFilesDir().getAbsolutePath()
                + APP_CACAHE_DIRNAME);

        File webviewCacheDir = new File(context.getCacheDir()
                .getAbsolutePath() + "/webviewCache");

        if (webviewCacheDir.exists()) {
            deleteFile(webviewCacheDir);
        }
        if (appCacheDir.exists()) {
            deleteFile(appCacheDir);
        }
    }

    static private void deleteFile(File file) {

        if (file.exists()) {
            if (file.isFile()) {
                file.delete();
            } else if (file.isDirectory()) {
                File files[] = file.listFiles();
                for (int i = 0; i < files.length; i++) {
                    deleteFile(files[i]);
                }
            }
            file.delete();
        }
    }
}

Related Tutorials