title: Block a URL in a WebView on Android
body: <p>I want to block a link from loading within a Webview.</p>
  <p><strong>Code</strong></p>
  <pre><code>public class WebMy extends Activity {
  
  
     
      private WebView mWebview;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          
              setContentView(R.layout.pantalla);
              getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);  
              
      
               
              mWebview  = new WebView(this);
              mWebview.setWebViewClient(new WebViewClient()); 
              mWebview.getSettings().setJavaScriptEnabled(true); // Enable JavaScript.
  
              mWebview .loadUrl(&quot;http://www.myweb.com&quot;);
              setContentView(mWebview );
             
      }
  </code></pre>
  <p><strong>Potential Solution</strong></p>
  <pre><code>public class MyWebViewClient extends WebViewClient {
      public boolean shuldOverrideKeyEvent (WebView view, KeyEvent event) {
           // Do something with the event here.
           return true;
      }
  
      public boolean shouldOverrideUrlLoading (WebView view, String url) {
          if (Uri.parse(url).getHost().equals(&quot;www.google.com&quot;)) {
               // This is my web site, so do not override; let my WebView load the page.
               return false;
          }
  
          // Reject everything else.
          return true;
      }
  }
  </code></pre>
  <p>I don´t know how I have to use this in my code. For example, if I want to block this url <code>http://www.myweb.com/pepito</code>. How can I do this with this code? Thank you.</p>