0

I am using WebView to render local HTML pages loaded from a string, and for security reasons need to block loading any external resources, but need to notify the user if anything was actually blocked and give the user an option to fully load the page with remote images/scripts.

I'm initially blocking network resources with webView.getSettings().setBlockNetworkLoads(true). This works well. Next I need to determine if the loaded HTML content actually contained any references to external networked resources that were blocked. Can anyone please tell me how to do that?

I would like this to work with API 8

Marcin
  • 2,399
  • 3
  • 17
  • 15

1 Answers1

0

You need to do the following:

class MyWebViewClient extends WebViewClient { 
    @Override
    public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
        // This method will get called when resources are to be loaded
        return new WebResourceResponse(null, null, new ByteArrayInputStream(new byte[0]));
    }
}

Then assign this client to your webview and handle resource loading in the above method.

This way you should be able to disable loading external resources without using the setBlockNetworkLoads(true) method and get the callback at the same time.

Rosomack
  • 271
  • 2
  • 8
  • When I try this, the clicks are no longer interpreted by default browser but loaded inside my WebView .. How do I default to the standard browser for click events? – Marcin Nov 30 '13 at 16:41