1

How can I implement the following WebClient method in in Android 4.4.4 or previous versions:

shouldInterceptRequest(WebView view, WebResourceRequest request)

N.B : I need this method with the parameter WebResourceRequest.

mWebView.setWebViewClient(new WebViewClient() {
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
        //Do Stuff
    }
});
TH3Under
  • 11
  • 2

1 Answers1

1

shouldInterceptRequest(WebView view, WebResourceRequest request) does not exist prior to API Level 21 (Android 5.0). If your minSdkVersion is below 21, but your compileSdkVersion is 21 or higher, you can implement that method, but it will only be called on Android 5.0+ devices.

For the older devices, you have no choice but to also implement the earlier form of shouldInterceptRequest(). Or, skip this functionality entirely on older devices. Newer devices can still use the newer callback, but you cannot somehow "retcon" older devices to know about WebResourceRequest and the older callback.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491