我有一个WebView,其中我加载了一个自定义链接的页面(如app:// action)。我在清单文件中注册了url模式,当我点击链接时,我的Activity的onResume()方法被调用了正确的数据,它工作正常。如何拦截WebView(android)中的url加载?
我的问题是,WebView仍然尝试加载链接,并且我的WebView最终显示“Web页面不可用”消息。我不想那样。
如何防止WebView加载网址?
这里是我的代码:
WebView banner = ...
banner.setWebViewClient(new WebViewClient() {
@Override
public void onLoadResource(WebView view, String url) {
if (url.startsWith("app://")) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url), getContext(), Main.class);
//startActivity(i);
}
}
}
banner.loadUrl("url_to_the_banner");
该死!我只是在参考中错过了!谢啦! – Alexis