从本地code进行的WebView的访问localStorage的 [英] Access localStorage of a WebView from native code

查看:386
本文介绍了从本地code进行的WebView的访问localStorage的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序商店的网页进行离线访问使用的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,但根据这个答案,这不是一个好主意,因为数据库格式的Andr​​oid版本之间的变化。

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的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆