2

I'm using a webview and I prefer cache getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);

But I need to know if a web page is being loaded for the first time, or whether its coming from cache.

I can't see a way to do this except manually cache the pages myself. Does anyone know a way to interrogate the cache, the webview must be doing this behind the scenes!

serenskye
  • 3,467
  • 5
  • 35
  • 51
  • Nope questioner wants to know when a cache is used if a connection cannot be established. They let the connection fail before using the cache, I cannot use this for my case. – serenskye Apr 11 '13 at 16:16
  • Why do you want to do this ? – Halim Qarroum Apr 11 '13 at 16:23
  • I have a progressBar and screen dimmer that appear when a webpage is loading, but I don't want to show it if the page is cached, there is no need and it makes the flow feel clunky. – serenskye Apr 11 '13 at 16:36
  • Chrome does also show a progress bar even when the page is cached, and it does not feel clunky. – Halim Qarroum Apr 11 '13 at 17:04
  • Thanks, but that does not help, I'm not looking for UI tips, its something that needs to be implemented for this particular usecase – serenskye Apr 11 '13 at 17:05

1 Answers1

0

Firstly you would have to set up a WebViewClient/WebChromeClient for your webView. You might wanna look at the WebViewClient/WebChromeClient classes respectively. There's a bunch of APIs listed under them, I've chalked out some of them which might be of interest to you: (Excerpts from Android Developer's Site)

/********WebChromeClient CLASS******/

public void getVisitedHistory (ValueCallback callback)

Obtains a list of all visited history items, used for link coloring

/*********WebStorage CLASS ****/

public void getOrigins (ValueCallback callback)

Gets the origins currently using either the Application Cache or Web SQL Database APIs. This method operates asynchronously, with the result being provided via a ValueCallback. The origins are provided as a map, of type Map, from the string representation of the origin to a WebStorage.Origin object.

If none of these seem to do the trick then you could rely on directly querying your application's cache directory (/data/data/my_app_package/cache under DDMS tab in eclipse IDE), programmatically you will be able to access the cache directory using the getCacheDir() API. Please refer to How do I view Android application specific cache? for the exact details.

Community
  • 1
  • 1
Sdr
  • 1,090
  • 9
  • 8