Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete/Erase a particular url from Android web view history?

Is it possible to erase a specific url from the android's webview history? I Google a lot but was not able to find any sol, even i checked the api's documentation and i think there is no direct way to do the same. have a look at below code:

// getting the whole list of web view's history....
WebBackForwardList list = wv.copyBackForwardList();
// getting previuous item/link 
String lastUrl = list.getItemAtIndex(list.getCurrentIndex()-1).getUrl();

From 2nd line of code it is clear that it is possible to play around with history, so i think there must be some way or trick to delete a particular link from web view history. Does it makes any sense to you guys?

Any code snippet or any link will highly be appreciated.

thanks,

like image 251
Mohit Avatar asked Jan 09 '13 07:01

Mohit


1 Answers

Well, not sure if you actually can play around with the back forward list. I would assume it's a copy - at least that's what the name suggest.

However, you can manipulate the back stepping to some degree. In my case I exit the application already when user tries to step back from second page towards first page.

  @Override
  public boolean dispatchKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            if ((action == KeyEvent.ACTION_DOWN) && myWebView.canGoBack() ) {
                WebBackForwardList list = myWebView.copyBackForwardList();
                String lastUrl = list.getItemAtIndex(list.getCurrentIndex()-1).getUrl().toString();

                // Exit if index == 1, i.e. currently on 2nd page
                if (list.getCurrentIndex() == 1) {
                    finish();
                } else ...

You could step over also other other pages by combining stuff from above and overloading url loading:

            @Override
            public boolean shouldOverrideUrlLoading(WebView  view, String  url){
                 view.loadUrl(url);
                 return true;
            }
like image 124
SBa Avatar answered Sep 22 '22 16:09

SBa