1

Is there any way to get the currently successfully loaded and not loaded files from URL into android webview. That is, if I am loading the following,

  • 1.js, 2.js, 3.js
  • 1.css, 2.css, 3.css

in html page and load the html file into android webview.

I need to list the loaded files in webview and also which are unable to load into android webview. I tried using the onConsoleMessage() from WebchromeClient which detects only the console error alone. This method not getting the error messages for css image.

Is this possible to list the files from URL?

Karthick
  • 1,241
  • 5
  • 20
  • 43

1 Answers1

1

You can get the list of resources the WebView is trying to load by overriding WebViewClient.shouldInterceptRequest like so:

class MyWebViewClient extends WebViewClient {

    @Override
    public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
        android.util.Log.i("MyWebViewClient", "attempting to load resource: " + url);
        return null;
    }

    @Override
    public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
        android.util.Log.i("MyWebViewClient", "attempting to load resource: " + request.getUrl());
        return null;
    }

}

Remember that shouldInterceptRequest is called on a background thread and so you need synchronize access to any shared data structures.

There is no Java API to find out whether the WebView has successfully loaded a given resource though.

marcin.kosiba
  • 3,221
  • 14
  • 19
  • This is works fine, but I am not able to find shouldInterceptRequest() with 3 parameters. – Karthick Jan 07 '15 at 10:40
  • @Karthick - what? there is no `shouldInterceptRequest` with 3 parameters, I never said there is one. The second version of shouldInterceptRequest is only available at targetSdk >= 21 – marcin.kosiba Jan 07 '15 at 11:47
  • Thanks for the clarification. I found that method and learned about it. – Karthick Jan 08 '15 at 04:19