Cordova 2.1.0 を使用して Android プラグインを開発しています。
プラグインコードは以下の通り
package org.apache.cordova.example;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class MyTestPlugin extends Plugin {
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackId The callback id used when calling back into JavaScript.
* @return A PluginResult object with a status and message.
*/
public PluginResult execute(String action, JSONArray args, String callbackId) {
try {
if (action.equals("echo")) {
String echo = args.getString(0);
if (echo != null && echo.length() > 0) {
return new PluginResult(PluginResult.Status.OK, echo);
} else {
return new PluginResult(PluginResult.Status.ERROR);
}
} else {
return new PluginResult(PluginResult.Status.INVALID_ACTION);
}
} catch (JSONException e) {
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
}
HTML/JS コード
<script type="text/javascript" src="cordova-2.1.0.js"></script>
<script type="text/javascript">
window.echo = function(str, callback) {
alert('Started');
cordova.exec(callback, callback, "MyTestPlugin", "echo", [str]);
alert('The END');
};
window.onload = function () {
alert('1st Step');
window.echo("echo", function(echoValue) {
alert(echoValue == "echo"); // should alert true.
});
alert('SecondStep');
};
</script>
</html>
構成.xml
しかし、プラグインを呼び出すことができません。誰かがこの問題を修正するのを手伝ってくれませんか?