gpt4 book ai didi

javascript - 从 native 代码访问 WebView 的 localStorage

转载 作者:行者123 更新时间:2023-11-30 03:14:16 25 4
gpt4 key购买 nike

我的应用程序使用 WebView 存储网页以供离线访问。

我需要通过 native 代码访问这些页面的缓存图像。

我首先尝试(未成功)读取 ApplicationCache.db,但根据 this answer ,这不是一个好主意,因为 Android 版本之间的数据库格式会发生变化。

我想到了在我的网页上使用 localStorage。是否可以从 native 代码访问存储的信息?

最佳答案

在 Android 4.4 上,您可以使用 WebView.evaluateJavascript API 从 javascript fragment 中获取结果,即您可以查询 localStorage 并解析返回的结果。在 4.4 之前,我认为使用 JS 桥将是你唯一合理的选择。我猜你会在你的 javascript 中连接到 StorageEvent 监听器的桥(这种方法也适用于 4.4)。

关于javascript - 从 native 代码访问 WebView 的 localStorage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20418337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com