Stop android browser from loading URL

被刻印的时光 ゝ 提交于 2019-12-25 02:11:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!