BooDoo BooDoo - 6 months ago 39
Android Question

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);

}



});

Answer

Use this hope it helps

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

You don't need to do something more from that

Comments