Example usage for android.webkit WebView clearCache

List of usage examples for android.webkit WebView clearCache

Introduction

In this page you can find the example usage for android.webkit WebView clearCache.

Prototype

public void clearCache(boolean includeDiskFiles) 

Source Link

Document

Clears the resource cache.

Usage

From source file:de.mkrtchyan.recoverytools.SettingsFragment.java

public static void showChangelog(Context AppContext) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(AppContext);
    dialog.setTitle(R.string.changelog);
    WebView changes = new WebView(AppContext);
    changes.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    changes.setWebViewClient(new WebViewClient());
    changes.loadUrl(Constants.CHANGELOG_URL);
    changes.clearCache(true);
    dialog.setView(changes);//w w w  . j a  v a 2s. c  o m
    dialog.show();
}

From source file:de.baumann.browser.helper.helper_webView.java

public static void closeWebView(Activity from, WebView webView) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);
    if (sharedPref.getBoolean("clearCookies", false)) {
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookies(null);
        cookieManager.flush();/*  w  w  w .  j av a  2 s .  co m*/
    }

    if (sharedPref.getBoolean("clearCache", false)) {
        webView.clearCache(true);
    }

    if (sharedPref.getBoolean("clearForm", false)) {
        webView.clearFormData();
    }

    if (sharedPref.getBoolean("history", false)) {
        from.deleteDatabase("history.db");
        webView.clearHistory();
    }
    helper_main.isClosed(from);
    sharedPref.edit().putString("started", "").apply();
    from.finishAffinity();
}

From source file:com.just.agentweb.AgentWebUtils.java

static void clearWebViewAllCache(Context context, WebView webView) {

    try {//from w ww .  j a  v a2 s . c  om

        AgentWebConfig.removeAllCookies(null);
        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        context.deleteDatabase("webviewCache.db");
        context.deleteDatabase("webview.db");
        webView.clearCache(true);
        webView.clearHistory();
        webView.clearFormData();
        clearCacheFolder(new File(AgentWebConfig.getCachePath(context)), 0);

    } catch (Exception ignore) {
        //ignore.printStackTrace();
        if (AgentWebConfig.DEBUG) {
            ignore.printStackTrace();
        }
    }
}

From source file:org.noise_planet.noisecapture.MapActivity.java

public void loadWebView() {
    WebView leaflet = (WebView) findViewById(R.id.webmapview);
    WebSettings webSettings = leaflet.getSettings();
    webSettings.setJavaScriptEnabled(true);
    leaflet.clearCache(true);
    leaflet.setInitialScale(200);/*from  w w  w.  jav  a  2 s .co m*/
    String location = "";
    if (builder != null && validBoundingBox) {
        LatLng latLng = builder.build().getCenter();
        location = "/#18/" + latLng.latitude + "/" + latLng.longitude;
    }
    leaflet.loadUrl("http://onomap.noise-planet.org" + location);
}

From source file:org.schabi.newpipe.ReCaptchaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recaptcha);

    // Set return to Cancel by default
    setResult(RESULT_CANCELED);//ww w  .ja  v  a 2  s.  c  o m

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.reCaptcha_title);
        actionBar.setDisplayShowTitleEnabled(true);
    }

    WebView myWebView = (WebView) findViewById(R.id.reCaptchaWebView);

    // Enable Javascript
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    ReCaptchaWebViewClient webClient = new ReCaptchaWebViewClient(this);
    myWebView.setWebViewClient(webClient);

    // Cleaning cache, history and cookies from webView
    myWebView.clearCache(true);
    myWebView.clearHistory();
    android.webkit.CookieManager cookieManager = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.removeAllCookies(new ValueCallback<Boolean>() {
            @Override
            public void onReceiveValue(Boolean aBoolean) {
            }
        });
    } else {
        cookieManager.removeAllCookie();
    }

    myWebView.loadUrl(YT_URL);
}

From source file:org.openqa.selendroid.server.model.SelendroidWebDriver.java

private void configureWebView(final WebView view) {
    ServerInstrumentation.getInstance().runOnUiThread(new Runnable() {

        @Override/*from   w  w  w.j a v  a 2 s.c om*/
        public void run() {
            view.clearCache(true);
            view.clearFormData();
            view.clearHistory();
            view.setFocusable(true);
            view.setFocusableInTouchMode(true);
            view.setNetworkAvailable(true);
            view.setWebChromeClient(new MyWebChromeClient());

            WebSettings settings = view.getSettings();
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setSupportMultipleWindows(true);
            settings.setBuiltInZoomControls(true);
            settings.setJavaScriptEnabled(true);
            settings.setAppCacheEnabled(true);
            settings.setAppCacheMaxSize(10 * 1024 * 1024);
            settings.setAppCachePath("");
            settings.setDatabaseEnabled(true);
            settings.setDomStorageEnabled(true);
            settings.setGeolocationEnabled(true);
            settings.setSaveFormData(false);
            settings.setSavePassword(false);
            settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
            // Flash settings
            settings.setPluginState(WebSettings.PluginState.ON);

            // Geo location settings
            settings.setGeolocationEnabled(true);
            settings.setGeolocationDatabasePath("/data/data/selendroid");
        }
    });
}

From source file:com.example.ruby.mygetgps.ui.activities.MainActivity.java

private void setupWebView() {
    WebView webview = (WebView) findViewById(R.id.webview);
    webview.setWebChromeClient(new WebChromeClient() {
        public void onGeolocationPermissionsShowPrompt(String origin,
                GeolocationPermissions.Callback callback) {
            callback.invoke(origin, true, false);
        }/*from   ww  w  .  j av  a 2  s.  c  o m*/
    });
    webview.setWebViewClient(new WebViewClient());
    webview.clearCache(true);
    webview.clearHistory();
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webview.loadUrl("https://getgpsserverrails-0.herokuapp.com/summaries");
}

From source file:org.esupportail.nfctagdroid.NfcTacDroidActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ESUP_NFC_TAG_SERVER_URL = getEsupNfcTagServerUrl(getApplicationContext());
    //To keep session for desfire async requests
    CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
    LocalStorage.getInstance(getApplicationContext());
    Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(getApplicationContext()));
    setContentView(R.layout.activity_main);
    mAdapter = NfcAdapter.getDefaultAdapter(this);
    checkHardware(mAdapter);// ww w .j a  v a 2  s.  co  m
    localStorageDBHelper = LocalStorage.getInstance(this.getApplicationContext());
    String numeroId = localStorageDBHelper.getValue("numeroId");
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String imei = telephonyManager.getDeviceId();
    url = ESUP_NFC_TAG_SERVER_URL + "/nfc-index?numeroId=" + numeroId + "&imei=" + imei + "&macAddress="
            + getMacAddr() + "&apkVersion=" + getApkVersion();
    view = (WebView) this.findViewById(R.id.webView);
    view.clearCache(true);
    view.addJavascriptInterface(new LocalStorageJavaScriptInterface(this.getApplicationContext()),
            "AndroidLocalStorage");
    view.addJavascriptInterface(new AndroidJavaScriptInterface(this.getApplicationContext()), "Android");

    view.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int progress) {
            if (progress == 100) {
                AUTH_TYPE = localStorageDBHelper.getValue("authType");
            }
        }

        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            log.info("Webview console message : " + consoleMessage.message());
            return false;
        }

    });

    view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            view.reload();
            return true;
        }
    });
    view.getSettings().setAllowContentAccess(true);
    WebSettings webSettings = view.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDatabasePath(this.getFilesDir().getParentFile().getPath() + "/databases/");

    view.setDownloadListener(new DownloadListener() {
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }

    });

    view.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
        }
    });

    view.loadUrl(url);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

From source file:com.air.mobilebrowser.BrowserActivity.java

/** 
 * Configure a webview to use the activity as
 * its client, and update its settings with 
 * the desired parameters for the activity.
 * @param webView the webview to configure.
 *///from w  ww  . j  ava  2s .c  o m
private void configureWebView(WebView webView) {
    webView.clearCache(true);
    webView.setWebViewClient(new SecureWebClient(this));

    WebSettings settings = mWebView.getSettings();
    settings.setBuiltInZoomControls(true);
    settings.setJavaScriptEnabled(true);
    //      settings.setPluginState(PluginState.ON_DEMAND);
    settings.setPluginState(PluginState.ON);
    settings.setAllowFileAccess(true);
    settings.setAllowContentAccess(true);
    settings.setSaveFormData(false);
    settings.setSavePassword(false);
    webView.clearFormData();
    settings.setDomStorageEnabled(true);
    String defaultUserAgent = settings.getUserAgentString();

    StringBuilder sb = new StringBuilder();
    sb.append(defaultUserAgent);
    sb.append(" SmarterSecureBrowser/1.0");
    sb.append(" OS/");
    sb.append(mDeviceStatus.operatingSystem);
    sb.append(" Version/");
    sb.append(mDeviceStatus.operatingSystemVersion);
    sb.append(" Model/");
    sb.append(mDeviceStatus.model);

    settings.setUserAgentString(sb.toString());
}

From source file:io.selendroid.server.model.SelendroidWebDriver.java

private void configureWebView(final WebView view) {
    ServerInstrumentation.getInstance().getCurrentActivity().runOnUiThread(new Runnable() {

        @Override/*from  w ww . j  a  va  2  s.com*/
        public void run() {
            try {
                view.clearCache(true);
                view.clearFormData();
                view.clearHistory();
                view.setFocusable(true);
                view.setFocusableInTouchMode(true);
                view.setNetworkAvailable(true);
                // need to check the class name rather than checking instanceof
                // since when it is not an instanceof, it likely means the app under test
                // does not contain the Cordova project and this will cause a RuntimeException
                if (view.getClass().getSimpleName().equalsIgnoreCase("CordovaWebView")) {
                    CordovaWebView webview = (CordovaWebView) view;
                    CordovaInterface ci = null;
                    chromeClient = new ExtendedCordovaChromeClient(null, webview);
                } else {
                    chromeClient = new SelendroidWebChromeClient();
                }
                view.setWebChromeClient(chromeClient);

                WebSettings settings = view.getSettings();
                settings.setJavaScriptCanOpenWindowsAutomatically(true);
                settings.setSupportMultipleWindows(true);
                settings.setBuiltInZoomControls(true);
                settings.setJavaScriptEnabled(true);
                settings.setAppCacheEnabled(true);
                settings.setAppCacheMaxSize(10 * 1024 * 1024);
                settings.setAppCachePath("");
                settings.setDatabaseEnabled(true);
                settings.setDomStorageEnabled(true);
                settings.setGeolocationEnabled(true);
                settings.setSaveFormData(false);
                settings.setSavePassword(false);
                settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
                // Flash settings
                settings.setPluginState(WebSettings.PluginState.ON);

                // Geo location settings
                settings.setGeolocationEnabled(true);
                settings.setGeolocationDatabasePath("/data/data/selendroid");
            } catch (Exception e) {
                SelendroidLogger.error("Error configuring web view", e);
            }
        }
    });
}