问题描述
我的应用程序商店的网页进行离线访问使用的WebView。
My application stores web pages for offline access using a WebView.
我需要通过本地code访问这些网页的缓存图像。
I need to access the cached images of those pages via native code.
我第一次尝试(失败)读ApplicationCache.db,但根据,这不是一个好主意,因为数据库格式的Android版本之间的变化。
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.
我有我的网页上使用本地存储的想法。是否有可能访问从本地code存储的信息?
I had an idea of using localStorage on my web page. Is it possible to access the stored information from native code?
推荐答案
在Android 4.4系统,您可以使用WebView.evaluateJavascript API来获取结果从JavaScript片段回来,即你可以询问的localStorage和分析结果返回。在此之前4.4,我想用JS桥将是你唯一合理的选择。我猜你会挂钩桥到StorageEvent监听器在JavaScript(这种方法会在4.4工作,太)。
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).
这篇关于从本地code进行的WebView的访问localStorage的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!