如何在 SL4A 上从 python 调用 javascript 方法?

发布于 2024-11-05 13:20:10 字数 273 浏览 4 评论 0原文

我正在使用 Python 和 SL4A 编写 Android 应用程序。该应用程序使用我希望刷新的网络视图。我计划通过在包装 doRefresh() javascript 函数中利用 javascript location.replace() 来实现此目的。我遇到的问题是我不知道如何从 Python 代码的主事件循环中调用 javascript 函数。

有没有办法直接调用方法呢?

或者

有没有办法通过按钮的 onClick 和模拟屏幕点击来间接调用该方法?

谢谢。

I am writing an Android app using Python and SL4A. The app uses a webview that I wish to refresh. I plan on doing this by utilising javascript location.replace() within a wrapping doRefresh() javascript function. The problem I have is that I do not know how to call the javascript function from within my main event loop within the Python code.

Is there a way to directly call the method?

or

Is there a way to indirectly call the method say via a button's onClick and a mimic screen tap?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤感在游骋 2024-11-12 13:20:10

您需要在 JavaScript 中等待刷新事件(这将是自定义事件),该 JavaScript 正在等待从 Python 脚本发布的事件。 JavaScript 和 Python 之间的唯一通信层是通过事件。

You'll need to wait for a refresh event (this would be a custom event) in your JavaScript that is waiting for an event posted from your Python script. The only communication layer between JavaScript and Python is via events.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文