问题
Is there any way to stop android native browser from being loading specific URL (eg. xyz.com) provided by my app and show notification about blocking ? If we can't stop then how to redirect browser to that another HTML page like otherPage.html (that is saved in sdcard) whenever xyz.com is visited?
I am busting my head into for many days with lot of searching, but no luck so far.
Any example/tutorial would be great.
Bundle Thanks
回答1:
You can create a WebViewClient and "filter" specific url:
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
if(url.equals("xyz.com")){
view.loadUrl("www.otherurl.com");
}
return false; //we handle url loading on our webview
}
});
回答2:
This may work using Intents. Whenever an app opens an URL, a specific intent is created and the browser catches it. And on my device, the standard browser creates intents and catches them itself every time, even if I just click on a link inside the browser window.
So just write a small app which catches the browser intents (the link above and vogel/a should help), compares the given URL with the blacklist and either displays the warning or forwards the intent to the browser. Now the user just has to specify your app as standard for this type of intent and then you should be fine.
来源:https://stackoverflow.com/questions/21662785/stop-android-browser-from-loading-url