简体   繁体   English

用于android的cordova自定义插件

[英]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.

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