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);
}
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) {
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With