API21中的shouldInterceptRequest参数更

API21中的shouldInterceptRequest参数更

本文介绍了如何处理API21中的shouldInterceptRequest参数更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在API21中,Google修改了shouldInterceptRequest方法以使用WebResourceRequest request而不是String url.有什么办法可以编写扩展WebViewClient的通用类并处理这两种方法?我的最低API版本是18.

In API21 Google modified shouldInterceptRequest method to use WebResourceRequest request instead of String url.Is there any way I could write a generic class extending WebViewClient and handle both methods?My minimum API version is 18.

谢谢克里斯汀(Krystian)

ThanksKrystian

推荐答案

否,他们添加了 second shouldInterceptRequest()方法.两者都可以在API Level 21+中获得; String变体在API Level 11+上可用.虽然String被标记为已弃用,但String变体应在相当长的时间内得到支持,以实现向后兼容.

No, they added a second shouldInterceptRequest() method. Both are available in API Level 21+; the String variant is available on API Level 11+. While the String one is marked as deprecated, the String variant should be supported for quite some time, for backwards compatibility.

shouldInterceptRequest()版本的WebResourceRequest版本的内置实现仅调用shouldInterceptRequest()String实现:

The built-in implementation of the WebResourceRequest version of shouldInterceptRequest() simply calls the String implementation of shouldInterceptRequest():

public WebResourceResponse shouldInterceptRequest(WebView view,
        WebResourceRequest request) {
    return shouldInterceptRequest(view, request.getUrl().toString());
}

(来自源代码截至目前)

因此,您有两种选择:

  1. 只需覆盖String版本,如果不需要WebResourceRequest,它将在所有相关的API级别上使用.

  1. Just override the String edition, if you do not need the WebResourceRequest, and it will be used on all relevant API levels.

同时覆盖这两个方面,知道WebResourceRequest版本将在API级别21+上使用,而String版本将在API级别11-20上使用.

Override both, knowing that the WebResourceRequest one will be used on API Level 21+ and the String edition will be used on API Levels 11-20.

这篇关于如何处理API21中的shouldInterceptRequest参数更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 03:47