I've done quite a bit of research and can't seem to find why this isn't working. What I have is Cordova based Android app in Eclipse running Cordova 2.7.0. I want to build a simple plugin that just alerts the user when it has completed.
My index.html
<head>
<script type="text/javascript" src="cordova-2.7.0.js"></script>
<script>
window.func = function(str,callback){
alert("Outside Call Working");
cordova.exec(callback, function(err){alert(err)},"HelloPlugin","echo", [str]);
}
function callPlugin(str){
alert("JS Working");
window.func(str,function(){
alert("Done!");
});
}
</script>
</head>
<body>
<h2>PluginTest</h2>
<a onclick="callPlugin('Plugin Working!')">Click me</a>
</body>
My config.xml line where I add the plugin
<plugin name="HelloPlugin" value="org.apache.cordova.plugin.HelloPlugin" />
And my actual plugin HelloPlugin.java that is in src/com/example/plugintest right next to MainActivity.java
package com.example.plugintest;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
public class HelloPlugin extends CordovaPlugin{
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
/*if(action.equals("echo")){
String message = args.getString(0);
callbackContext.success(message);
return true;
}*/
callbackContext.success(action);
return true;
}
}
Any help is greatly appreciated!
In this line
window.func = function(str,callback){
alert("Outside Call Working");
cordova.exec(callback, function(err){alert(err)},"HelloPlugin","echo", [str]);
}
put like this
window.func = function(str,callback){
alert("Outside Call Working");
cordova.exec(callback, function(err){alert(err)},"org.apache.cordova.plugin.HelloPlugin","echo", [str]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With