I'm trying to create a plugin for Cordova 3.0 on Android with the Echo example but it's not working.
I added <plugin name="MMSSender" value="my.package.mms.MMSSender" />
to my config.xml
(from www
and did cordova build
)
Then I created a new Class MMSSender in my.package.mms
with the example code given ;
package my.package.mms;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class Echo extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("echo")) {
String message = args.getString(0);
this.echo(message, callbackContext);
return true;
}
return false;
}
private void echo(String message, CallbackContext callbackContext) {
if (message != null && message.length() > 0) {
callbackContext.success(message);
} else {
callbackContext.error("Expected one non-empty string argument.");
}
}
}
And I added the code below the my main js file. Edit : the code in wrapped in deviceready
event
window.echo = function(str, callback) {
cordova.exec(callback, function(err) {
callback(err);
}, "MMSSender", "echo", [str]);
};
window.echo("echome", function(echoValue) {
alert(echoValue);
});
The problem is that echoValue contains "Class not found".
Any idea ?
Do I have to modify the plugins
folder ?
Import your phonegap(Cordova) project into your IDE (Eclipse + ADT) as an existing android project. Then you will see what is wrong with your plugin java code. In my case the problem was wrong package name and it resulted in class not found message from javascript callback.
Usually you prepare a separate package with a plugin.xml file, java class and js file and then add it to the app using the
cordova plugin add
command.Anyway, one thing you may miss is the link between the name of the parameter of the cordova.exec function and your plugin class.
You should modifiy the file
res/xml/config.xml
and add lines like this :EDIT:
In your repo, you need to correct the imports in MMS.java:
replace
with
Once that corrected, you should be able at least to build the project.