Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webview.goBack() method doesnt invoke shouldOverrideUrlLoading method

I want every page loaded in my app go through the url override method ( where i do some html modifications ). How can i achieve this?.

public boolean shouldOverrideUrlLoading(WebView view, String url) {
    // do some html modifcations (myhtml)
    view.loadDataWithBaseURL(url, myhtml, "text/html", "utf-8", url);
    return false;
}

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && web1.canGoBack()) {
        web1.goBack(); // go back 1 step
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
like image 306
murshidm Avatar asked Oct 06 '11 09:10

murshidm


1 Answers

on page finished method you will get the url and you can reload the url

       @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);

        }
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            _dialog.dismiss();
        }

        @Override
        public void onReceivedError(WebView view, int errorCode,String description, String failingUrl) {
            // TODO Auto-generated method stub
            super.onReceivedError(view, errorCode, description, failingUrl);
            try{
                _dialog.dismiss();
                Toast.makeText(Showwebviewlatestnews.this, "NO Internet Connection Available", Toast.LENGTH_SHORT);
            }catch (Exception e) {

            }
        }
like image 65
Harsh Dev Chandel Avatar answered Nov 18 '22 22:11

Harsh Dev Chandel