我可以使用shouldInterceptRequest阻止Android中的特定呼叫吗? [英] Can I use shouldInterceptRequest to block a particular call in Android?

查看:203
本文介绍了我可以使用shouldInterceptRequest阻止Android中的特定呼叫吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了以下代码

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也会在后台加载.如何停止加载网址?

However, while the alert is displayed my console also prints the log, besides which the url is also loaded in the background. How can I stop the url from loading?

请更正我对该功能的理解.

Please correct my understanding of this function.

谢谢

推荐答案

如果在shouldInterceptRequest中返回null,则表示WebView将继续照常加载资源.

If you return null in shouldInterceptRequest, it means that the WebView will continue to load the resource as usual.

这就是为什么看到URL仍在加载的原因.

This is why you see the URL still being loaded.

为了拦截和阻止呼叫,您需要返回自己的(非空)数据.

In order to intercept and block the call, you need to return your own (Non-null) data instead.

这篇关于我可以使用shouldInterceptRequest阻止Android中的特定呼叫吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆