我创建了一个托管网站的android应用,该网站已经加载了一些外部链接“URL”。防止webview加载一些URL
所以我需要来阻止存储在/res/raw/
文件中的一些URL从webview加载。
我尝试覆盖shouldInterceptRequest(WebView view, String url)
但我不知道如何使用它。
我创建了一个托管网站的android应用,该网站已经加载了一些外部链接“URL”。防止webview加载一些URL
所以我需要来阻止存储在/res/raw/
文件中的一些URL从webview加载。
我尝试覆盖shouldInterceptRequest(WebView view, String url)
但我不知道如何使用它。
可以使用的WebViewClient
方法给主机应用程序有机会接管控制,当一个新的URL是有关当前WebView.If WebViewClient要加载的提供,返回
true
表示主机应用程序处理url,而返回false
表示当前WebView处理该url。
在代码:
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
[在机器人网页视图用于安全块某些URL](的可能的复制http://stackoverflow.com/questions/10121089/block-certain-urls-for-security -in-android-webview) – Massimo