我使用了下面的代码
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
alertsavedinternal(); //display an alert
Log.d("DEBUG", "Should intercept request" +url);
//log the url to console in debug mode.
return null;
}
但是,当显示警报时,我的控制台还会打印日志,此外,还会在后台加载 url。我怎样才能阻止 url 加载?
请纠正我对这个函数的理解。
谢谢
最佳答案
如果在 shouldInterceptRequest
中返回 null,则表示 WebView 将照常继续加载资源。
这就是您看到 URL 仍在加载的原因。
为了拦截和阻止调用,您需要返回自己的(非空)数据。
关于android - 我可以使用 shouldInterceptRequest 来阻止 Android 中的特定调用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16044554/