Android Cordova插件-Javascript从本机代码接收消息
如下文件所示: 我重写了一个方法Android Cordova插件-Javascript从本机代码接收消息,android,cordova,plugins,sencha-touch-2,Android,Cordova,Plugins,Sencha Touch 2,如下文件所示: 我重写了一个方法 @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if ("beep".equals(action)) { this.beep(args.getLong(0)); callbackContext.suc
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if ("beep".equals(action)) {
this.beep(args.getLong(0));
callbackContext.success();
return true;
}
return false; // Returning false results in a "MethodNotFound" error.
}
从Javascript中调用它,如下所示:
cordova.exec(<successFunction>, <failFunction>, <service>, <action>, [<args>]);
cordova.exec(,[]);
上面的java本机代码只返回布尔结果。如何使其返回字符串(或JSON)并使cordova.exec()接收它
p/s:我想使用java本机代码从电子邮件中读取JSON字符串(项目列表)。它将返回Javascript代码,以在Sencha Touch中呈现到列表中。您的问题的答案在您链接的文档页面中提供。检查页面上的最后一个代码示例:
private void echo(String message, CallbackContext callbackContext) {
if (message != null && message.length() > 0) {
callbackContext.success(message); //<-THIS LINE
} else {
callbackContext.error("Expected one non-empty string argument.");
}
}
并称之为:
cordova.exec(onSuccess, ...)
成功时,它应该输出传递的
消息的内容
字符串参数。Oh。谢谢你。这是我的大错。
cordova.exec(onSuccess, ...)