Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting webViewClient.shouldInterceptRequest() on android 2.x

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

like image 952
vishesh Avatar asked Oct 05 '22 08:10

vishesh


1 Answers

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().

like image 118
Oasis Feng Avatar answered Oct 10 '22 03:10

Oasis Feng