Example usage for android.webkit WebView clearHistory

List of usage examples for android.webkit WebView clearHistory

Introduction

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

Prototype

public void clearHistory() 

Source Link

Document

Tells this WebView to clear its internal back/forward list.

Usage

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();//  ww  w . ja v  a 2  s .  c om
    }

    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 {/* ww w .  j a v a2  s.c  o  m*/

        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:com.just.agentweb.AgentWebUtils.java

static final void clearWebView(WebView m) {

    if (m == null) {
        return;// www.j a va  2  s  . c  o m
    }
    if (Looper.myLooper() != Looper.getMainLooper()) {
        return;
    }
    m.loadUrl("about:blank");
    m.stopLoading();
    if (m.getHandler() != null) {
        m.getHandler().removeCallbacksAndMessages(null);
    }
    m.removeAllViews();
    ViewGroup mViewGroup = null;
    if ((mViewGroup = ((ViewGroup) m.getParent())) != null) {
        mViewGroup.removeView(m);
    }
    m.setWebChromeClient(null);
    m.setWebViewClient(null);
    m.setTag(null);
    m.clearHistory();
    m.destroy();
    m = null;

}

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);/*from  w w  w .j ava  2s.  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: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);
        }//ww w . j a  va2s. c om
    });
    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.openqa.selendroid.server.model.SelendroidWebDriver.java

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

        @Override/*from   w ww.  j  a v  a  2s  .co  m*/
        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.robandjen.comicsapp.FullscreenActivity.java

void showCurrentComic(String url) {
    if (url == null || url.isEmpty()) {
        url = mComicList.get(mCurComic).getURL();
    }//from ww  w. j  a  va 2 s  .  com

    final WebView contentView = (WebView) findViewById(R.id.fullscreen_content);
    contentView.stopLoading();

    //Load about:blank to clear any extra data and have a well defined URL in history
    contentView.loadUrl("about:blank");
    contentView.loadUrl(url);
    contentView.clearHistory();
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setTitle(mComicList.get(mCurComic).getName());
    }
    updateShare(url);

    ExpandableListView elv = (ExpandableListView) findViewById(R.id.comic_drawer);
    long packedPos = mAdapter.comicsPosToPackedPos(mCurComic);

    //Selection doesn't work if expandGroup isn't called or group already expanded. ?????
    elv.expandGroup(ExpandableListView.getPackedPositionGroup(packedPos));
    elv.setSelectedChild(ExpandableListView.getPackedPositionGroup(packedPos),
            ExpandableListView.getPackedPositionChild(packedPos), true);
    elv.setItemChecked(elv.getFlatListPosition(packedPos), true);
}

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

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

        @Override/* w w  w. j  a  va  2  s.  c om*/
        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);
            }
        }
    });
}

From source file:org.apache.cordova.engine.apiref.ImpSpecificWebViewClient.java

/**
 * Notify the host application that a page has finished loading.
 * This method is called only for main frame. When onPageFinished() is called, the rendering picture may not be updated yet.
 *
 *
 * @param view          The webview initiating the callback.
 * @param url           The url of the page.
 *//*from w  ww . j  a v a  2  s  . c o m*/
@Override
public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);
    // Ignore excessive calls.
    if (!isCurrentlyLoading) {
        return;
    }
    isCurrentlyLoading = false;
    LOG.d(TAG, "onPageFinished(" + url + ")");

    /**
     * Because of a timing issue we need to clear this history in onPageFinished as well as
     * onPageStarted. However we only want to do this if the doClearHistory boolean is set to
     * true. You see when you load a url with a # in it which is common in jQuery applications
     * onPageStared is not called. Clearing the history at that point would break jQuery apps.
     */
    if (this.doClearHistory) {
        view.clearHistory();
        this.doClearHistory = false;
    }

    // Clear timeout flag
    appView.loadUrlTimeout++;

    // Broadcast message that page has loaded
    this.appView.getPluginManager().postMessage("onPageFinished", url);

    // Make app visible after 2 sec in case there was a JS error and Cordova JS never initialized correctly
    if (this.appView.getVisibility() == View.INVISIBLE) {
        Thread t = new Thread(new Runnable() {
            public void run() {
                try {
                    Thread.sleep(2000);
                    cordova.getActivity().runOnUiThread(new Runnable() {
                        public void run() {
                            appView.getPluginManager().postMessage("spinner", "stop");
                        }
                    });
                } catch (InterruptedException e) {
                }
            }
        });
        t.start();
    }

    // Shutdown if blank loaded
    if (url.equals("about:blank")) {
        appView.getPluginManager().postMessage("exit", null);
    }
}

From source file:org.apache.cordova.CordovaWebViewClient.java

/**
 * Notify the host application that a page has finished loading.
 * This method is called only for main frame. When onPageFinished() is called, the rendering picture may not be updated yet.
 *
 *
 * @param view          The webview initiating the callback.
 * @param url           The url of the page.
 *//*from   w ww.ja v  a  2 s .c o  m*/
@Override
public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);
    // Ignore excessive calls.
    if (!isCurrentlyLoading) {
        return;
    }
    isCurrentlyLoading = false;
    LOG.d(TAG, "onPageFinished(" + url + ")");

    /**
     * Because of a timing issue we need to clear this history in onPageFinished as well as
     * onPageStarted. However we only want to do this if the doClearHistory boolean is set to
     * true. You see when you load a url with a # in it which is common in jQuery applications
     * onPageStared is not called. Clearing the history at that point would break jQuery apps.
     */
    if (this.doClearHistory) {
        view.clearHistory();
        this.doClearHistory = false;
    }

    // Clear timeout flag
    this.appView.loadUrlTimeout++;

    // Broadcast message that page has loaded
    this.appView.postMessage("onPageFinished", url);

    // Make app visible after 2 sec in case there was a JS error and Cordova JS never initialized correctly
    if (this.appView.getVisibility() == View.INVISIBLE) {
        Thread t = new Thread(new Runnable() {
            public void run() {
                try {
                    Thread.sleep(2000);
                    cordova.getActivity().runOnUiThread(new Runnable() {
                        public void run() {
                            appView.postMessage("spinner", "stop");
                        }
                    });
                } catch (InterruptedException e) {
                }
            }
        });
        t.start();
    }

    // Shutdown if blank loaded
    if (url.equals("about:blank")) {
        appView.postMessage("exit", null);
    }
}