BooDoo
BooDoo

Reputation: 635

Block a site in webview

In my apps webview i want to block some sites that users should not enter. For example how can i block all google sites (.com .fr etc.) without using

url.contains("google");

because some urls contain the word google but they dont browse to the site. For example: https://www.bing.com/search?q=google

Here is my code

web.setWebViewClient(new WebViewClient(){

                @Override
                public void onPageStarted(WebView webView, String webUrl, Bitmap favicon) {


                    if(webUrl.contains("google")){//not works good
                        //block
                    }

                     super.onPageStarted(webView, webUrl, favicon);

                }



        });

Upvotes: 3

Views: 549

Answers (1)

BooDoo
BooDoo

Reputation: 635

Sounds simple but it could be a solution. Use this:

if(url.startsWith("https://www.google"){
//block site
}

Not smart but remains a way to effectively manage url

Upvotes: 4

Related Questions