简体   繁体   English

使用插件与appView.addJavascriptInterface不同

[英]different using Plugin vs appView.addJavascriptInterface

I want to build a native apps in android using phonegap cordova. 我想使用phonegap cordova在android中构建本机应用程序。 I found 2 way to make my html file can comunicate to my java file. 我发现2种方法可以使我的html文件可以与我的java文件通信。 I can using appView.addjavascriptInterface or make my java file to be a plugin. 我可以使用appView.addjavascriptInterface或使我的java文件成为插件。 I want to now which way is the best. 我想现在哪种方式最好。 What is the diferences using plugin or appView.addJavascriptInterface? 使用插件或appView.addJavascriptInterface有什么不同?

Using a Cordova Plugin is the recommended approach to expose Java code to the JavaScript layer of your application. 使用Cordova插件是将Java代码公开到应用程序的JavaScript层的推荐方法。 Take a look at the Plugin Development Guide and Developing a Plugin on Android . 看看插件开发指南在Android上开发插件

addJavascriptInterface is part of Android WebView API and it's used inside of Apache Cordova's Android code . addJavascriptInterface是Android WebView API的一部分,它在Apache Cordova的Android代码中使用 There's at least one bug with Android 2.3 and that method you can avoid by using Apache Cordova's plugin system. Android 2.3中至少存在一个错误 ,使用Apache Cordova的插件系统可以避免这种方法。

What is the diferences using plugin or appView.addJavascriptInterface? 使用插件或appView.addJavascriptInterface有什么不同?

The difference is a Cordova Plugin is a higher level abstraction that allows you to consistently expose native code from various platforms (Android, iOS, among others), to the WebView running your JavaScript code. 不同之处在于Cordova插件是一种更高级别的抽象,允许您始终将来自各种平台(Android,iOS等)的本机代码暴露给运行JavaScript代码的WebView。 While the addJavascriptInterface is an Android-specific method that is part of the WebView API which is used Apache Cordova's Android code. 虽然addJavascriptInterface是一个Android特定的方法,它是使用Apache Cordova的Android代码的WebView API的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM