Chandu
Chandu

Reputation: 1059

Android WebView caching

I am writing an app where the user is present with a list of URLs. To make it appear more faster, I want to detect the Wi-Fi state and load the URLs in the background, so when the user picks a URL, they are quickly presented the data specially when they are connected to Wi-Fi. Is there a way I can do this?

Upvotes: 3

Views: 4539

Answers (1)

FunkTheMonk
FunkTheMonk

Reputation: 10938

Yes, using shouldInterceptRequest. Which you can use to detect if you have a cached version of the requested URL and return an input stream to the cache which the WebView will use instead of loading it from ze webz

For versions before honeycomb, it might be possible to use shouldOverrideUrlLoading, calling webview.loadData(datafromcache, "text/html", "UTF-8"); and return true.

Upvotes: 3

Related Questions