I have to make a webbrowser for android, so I want to try to block a site.
How can I do that?
Lets say your WebView id is myWebView then what you will do is this :
WebView wb = (WebView) findViewById(R.id.myWebView); wb.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.contains("http://yourBlockedUrl.com")){ //notify the user that this url is blocked return true; } return false; } }); by doing this you are overriding the url loading of your webview you can thus block a url from loading.
say you get the url sent as a string "www.google.com", from the edittext just do a check if this is a blocked url. for example
if( "www.google.com".equalsIgnoreCase(blocked_string)) { webview.setVisibility(View.GONE); warning_view.setVisibilty(View.VISIBLE); } or you could try overriding the shouldOverrideUrlLoading() in the WebViewClient class
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if(my_url.equals("www.google.com")){ //do something. } return true; } Creating and setting a WebViewClient subclass. It will be called when things happen that impact the rendering of the content, eg, errors or form submissions. You can also intercept URL loading here (via shouldOverrideUrlLoading()).
public void gotoUrl(View view) { EditText theEditText = (EditText)findViewById(R.id.urlTxt); theUrl = theEditText.getText().toString(); // // String blok= "http://www.teknojurnal.com"; webBrowserKu.loadUrl(theUrl); } my web browser when klik go, will process this, so what is the problem? why I cant do the steps from anything for blocking one site?