Question

I am overriding webViewClient.shouldInterceptRequest() to return common resources like images and js files from asset folder.But this is available for android >=3 .is there any alternative to use for android 2.x

I found onLoadResource() to provide similar behaviour but its return type is void

Was it helpful?

Solution

I've been digging this for a while, and the practical way I found so far to achieve the similar purpose is to implement a local HTTP proxy for this web view.

To set a proxy for webview, see this question: WebView android proxy

There're many open source HTTP proxy written in Java, like LittleProxy.


Yet another possible but complex way: use shouldOverrideUrlLoading() to capture all page requests but always return true. Fetch the content of page with your own code, then parse and replace all remote resources with local cached copies, and finally load the modified content with WebView.loadData().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top