Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Cordova插件-Javascript从本机代码接收消息_Android_Cordova_Plugins_Sencha Touch 2 - Fatal编程技术网

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, ...)