1

My application stores web pages for offline access using a WebView.

I need to access the cached images of those pages via native code.

I first tried (unsuccessfully) reading ApplicationCache.db, but according to this answer, it's not a good idea, since the database format changes between Android versions.

I had an idea of using localStorage on my web page. Is it possible to access the stored information from native code?

Community
  • 1
  • 1
Lizozom
  • 2,161
  • 2
  • 21
  • 38
  • ApplicationCache and local Storage are two different things. If you are using localstorage , this link could help you !- http://stackoverflow.com/questions/17615526/android-webview-localstorage – GemK Dec 06 '13 at 07:47
  • This answers clear the diffrence -http://stackoverflow.com/questions/9407220/in-androids-webview-whats-the-different-between-domstorage-database-ap?rq=1 – GemK Dec 06 '13 at 08:00
  • I know that they are two different things. I need to store something from within a webview and access it from native code. The application cache is inaccessible from the native code, so I'm trying to use localStorage as an alternative (for example I can store the images as strings in the local storage and then access it via the JS bridge). I was wondering if I could access the localStorage database directly from native code. Sorry if I wasn't clear enough. – Lizozom Dec 06 '13 at 15:34

1 Answers1

1

On Android 4.4, you could use the WebView.evaluateJavascript API to get a result back from a javascript snippet, i.e. you could interrogate localStorage and parse the result returned. Prior to 4.4, I think using a JS bridge will be your only reasonable option. I guess you'd hook up the bridge to a StorageEvent listener in your javascript (this approach would work in 4.4, too).

ksasq
  • 4,424
  • 2
  • 18
  • 10