[英]Custom plugin in cordova for android
I am using cordova in my android application and I want to use my custom plugins. 我在我的Android应用程序中使用cordova,我想使用我的自定义插件。 But I am getting error- exec() call to unknown plugin
但我得到error- exec()调用未知插件
this is my HTML
file. 这是我的
HTML
文件。
function callNativePlugin( returnSuccess ) {
HelloPlugin.callNativeFunction( nativePluginResultHandler, nativePluginErrorHandler, returnSuccess );
}
function nativePluginResultHandler (result) {
alert("SUCCESS: \r\n"+result );
}
function nativePluginErrorHandler (error) {
alert("ERROR: \r\n"+error );
}
function newCall(){
alert("function ready");
window.echo = function(str, callback) {
cordova.exec(callback, function(err) {
callback('Nothing to echo.');
}, "HelloPlugin", "echo", [str]);
};
window.echo("echome", function(echoValue) {
alert(echoValue == "echome"); // should alert true.
});
}
</script>
</head>
<body onload="onLoad()">
<button onclick="newCall();">Click to invoke the Native Plugin with an SUCCESS!</button>
<button onclick="callNativePlugin('error');">Click to invoke the Native Plugin with an ERROR!</button>
</body>
this is my js
file 这是我的
js
文件
var HelloPlugin = {
callNativeFunction: function (success, fail, resultType) {
return cordova.exec(success, fail, "com.webview.HelloPlugin", "HelloPlugin", [resultType]);
}
};
Plugin java
file 插件
java
文件
public class HelloPlugin extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
Log.i("Log msg","Log msg");
return false;
}
}
my Config.js
file 我的
Config.js
文件
<feature name="HelloPlugin">
<param name="com.webview.HelloPlugin" value="com.ecsoftware.HelloPlugin" />
</feature>
Your config.xml
should look like this: 您的
config.xml
应如下所示:
<feature name="com.webview.HelloPlugin">
<param name="android-package" value="com.ecsoftware.HelloPlugin" />
</feature>
Also remember this is the config.xml
file in your res/xml/
folder (and not the one in the www
folder). 还要记住这是
res/xml/
文件夹中的config.xml
文件(而不是www
文件夹中的那个)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.