Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
Prevent webview from loading some URLs

I create a android app that host website, the website loads some external links "URL".

I need to block some URLs that store in file on /res/raw/ from loading in webview.

I try override shouldInterceptRequest(WebView view, String url), but I don't know how use it.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use shouldOverrideUrlLoading

method of the WebViewClient

Give the host application a chance to take over the control when a new url is about to be loaded in the current WebView.If WebViewClient is provided, return true means the host application handles the url, while return false means the current WebView handles the url.

in code:

    public class MyWebViewClient extends WebViewClient {
    public boolean shouldOverrideUrlLoading (WebView view, String url) {
        if (Uri.parse(url).getHost().equals("http://Your_website_url")) {
             // This is my web site, so do not override; let my WebView load the page
             return false;
        }

        // reject anything other
        return true;
    }
}


mWebview.setWebViewClient(new MyWebViewClient());  //set the webviewClient
about 4 years ago · Santiago Trujillo Report

0

You have to override the method shouldOverrideUrlLoading (see here) of your WebViewClient, rather than the one you are overriding. Just return false if you want to load the page; true if you want to block loading.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!