android-在使用不推荐使用的版本时,对不推荐使用和不推荐使用的变体两次调用了shouldInterceptRequest

android-在使用不推荐使用的版本时,对不推荐使用和不推荐使用的变体两次调用了shouldInterceptRequest,第1张

概述我有webView覆盖shouldInterceptRequest方法:@RequiresApi(api=Build.VERSION_CODES.LOLLIPOP)@OverridepublicWebResourceResponseshouldInterceptRequest(WebViewview,WebResourceRequestrequest){WebResourceResponseresponse=proxy.getWebResourceResponse(

我有webVIEw覆盖shouldInterceptRequest方法:

@RequiresAPI(API = Build.VERSION_CODES.LolliPOP)@OverrIDepublic WebResourceResponse shouldInterceptRequest(WebVIEw vIEw, WebResourceRequest request) {    WebResourceResponse response = proxy.getWebResourceResponse(request.getUrl(), request.getmethod(), request.getRequestheaders());    if (response == null) {        return super.shouldInterceptRequest(vIEw, request);    } else {        return response;    }}@SuppressWarnings("deprecation")@OverrIDepublic WebResourceResponse shouldInterceptRequest(WebVIEw vIEw, String url) {    WebResourceResponse response = proxy.getWebResourceResponse(Uri.parse(url), "GET", null);    if (response == null) {        return super.shouldInterceptRequest(vIEw, url);    } else {        return response;    }}

问题是在棒棒糖上这两种方法都被调用了.因此,我认为我应该指定不赞成使用的版本仅应用于旧的AndroID版本.与RequiresAPI完全相反
如果可以通过制作复制粘贴类并使用if-else根据AndroID版本选择类来解决问题,但这确实很丑.

更新.更新以更好地反映问题.

解决方法:

默认实现WebViewClient in Android source codes从较新的版本调用不赞成使用的shouldInterceptRequest版本,将请求中的当前URL作为字符串传递:

@Deprecatedpublic WebResourceResponse shouldInterceptRequest(WebVIEw vIEw, String url){    return null;}public WebResourceResponse shouldInterceptRequest(WebVIEw vIEw, WebResourceRequest request){    return shouldInterceptRequest(vIEw, request.getUrl().toString());}

由于您从自定义WebVIEwClIEnt实现中调用了默认的Lollipop特定处理程序(当request为null时,使用super.shouldInterceptRequest(vIEw,request)),因此它将依次调用已弃用的处理程序的重写实现.

您不应从新的实现中调用super方法,以免执行不受欢迎的方法.

总结

以上是内存溢出为你收集整理的android-在使用不推荐使用的版本时,对不推荐使用和不推荐使用的变体两次调用了shouldInterceptRequest全部内容,希望文章能够帮你解决android-在使用不推荐使用的版本时,对不推荐使用和不推荐使用的变体两次调用了shouldInterceptRequest所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1091345.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存