问题
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.
Thanks Krystian
回答1:
Google modified shouldInterceptRequest method to use WebResourceRequest request instead of String url
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.
Is there any way I could write a generic class extending WebViewClient and handle both methods?
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());
}
(from the source code as of right now)
So, you have two choices:
Just override the
Stringedition, if you do not need theWebResourceRequest, and it will be used on all relevant API levels.Override both, knowing that the
WebResourceRequestone will be used on API Level 21+ and theStringedition will be used on API Levels 11-20.
来源:https://stackoverflow.com/questions/32669683/how-to-handle-shouldinterceptrequest-parameter-change-in-api21