[英]Call JavaScript API from Android Application
I am trying to build a native android application where I don't intend to use WEbview for my frontend.我正在尝试构建一个本地 android 应用程序,我不打算将 WEbview 用于我的前端。 I want to make API call to eWeLink ( https://github.com/skydiver/ewelink-api ) which is exposed for Javascript.我想让 API 调用 eWeLink ( https://github.com/skydiver/ewelink-api ),它是为 Javascript 公开的。 How can I achieve this in android?如何在 android 中实现这一点?
Solutions (from easiest to hardest IMO):解决方案(从最简单到最难的 IMO):
You could use a JS evaluator for Android.您可以为 Android 使用 JS 评估器。 See https://stackoverflow.com/a/22418086/9398629 .请参阅https://stackoverflow.com/a/22418086/9398629 。 LiquidCore https://github.com/LiquidPlayer/LiquidCore seems to be the standard choice. LiquidCore https://github.com/LiquidPlayer/LiquidCore似乎是标准选择。 LiquidCore's readme in GitHub has directions for adding NPM package dependencies. GitHub 中的 LiquidCore 自述文件包含添加 NPM package 依赖项的说明。
Use a WebView to execute code from that npm package.使用 WebView 从 npm package 执行代码。 Reference the results of your JS API calls in your Java code by doing something similar to this: https://stackoverflow.com/a/20377592/9398629 .通过执行与此类似的操作,在 Java 代码中引用 JS API 调用的结果: https://stackoverflow.com/a/20377 . Using evaluateJavascript
might be easiest.使用evaluateJavascript
可能是最简单的。
Re-write the ewelink-api
npm package in Java.重写Java中的ewelink-api
npm package。
So i had the same issue, so wrote a java api if you still need it that interfaces with the ewelink platform所以我有同样的问题,所以写了一个 java api 如果你仍然需要它来连接 ewelink 平台
you can get it here if you want http://ewelink-api-java.co.zw/如果你想要http://ewelink-api-java.co.zw/ ,你可以在这里得到它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.