问题描述
我想在自定义Webview客户端(不带JavaScript注入)中实现一种可以阻止广告的机制。是否可以捕获广告并将其替换为可信任来源的其他广告?
谢谢
I want to implement a mechanism in a custom webview client (without JavaScript injection) that can block ads. Is a way I can catch ads and replace them with other ads from a trusted source?Thanks
推荐答案
在您的自定义,您可以覆盖函数。
In your custom WebViewClient
, you can override the function shouldInterceptRequest(WebView, WebResourceRequest)
.
从Android :
因此,一般的想法是检查请求是否来自广告网址(大量黑名单过滤掉),然后返回不是广告的假资源。
So the general idea is to check if the request is coming from an ad URL (plenty of black list filters out there), then return a "fake" resource that isn't the ad.
有关更深入的解释和示例,我建议您检查一下将此。
For a more in depth explanation plus an example, I recommend checking out this blog post.
这篇关于Android在网络视图中屏蔽广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!