如何通过 Javascript 在 Phonegap 中调用本机函数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11609326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 13:48:40  来源:igfitidea点击:

How can I call native functions in Phonegap through Javascript?

javajavascriptandroidcordova

提问by tilak

I am developing an application for Android using PhoneGap. I have implemented some of the functions in Java. How can I call those Java functions using Javascript?

我正在使用 PhoneGap 为 Android 开发应用程序。我已经用Java实现了一些功能。如何使用 Javascript 调用这些 Java 函数?

回答by marwinXXII

there is a similar question https://stackoverflow.com/a/8733773/905565

有一个类似的问题https://stackoverflow.com/a/8733773/905565

Write your own plugin, or provide JavaScript interface with addJavascriptInterfacemethod of WebView

编写自己的插件,或者通过WebView的addJavascriptInterface方法提供JavaScript接口

Access to webview in your phonegap activity with this.webView

在您的 phonegap 活动中访问 webview this.webView