Javascript Phonegap,插件执行函数不';我好像没接到电话
我从PhoneGap开始,试图编写我的第一个Android插件。我基于文档中的Echo示例。它编译并安装,但对exec的调用似乎不起作用。有人能提出什么问题吗?index.html、Java代码和config.xml如下所示。我收到“running exec”的警报消息,但什么都没有Javascript Phonegap,插件执行函数不';我好像没接到电话,javascript,android,cordova,plugins,Javascript,Android,Cordova,Plugins,我从PhoneGap开始,试图编写我的第一个Android插件。我基于文档中的Echo示例。它编译并安装,但对exec的调用似乎不起作用。有人能提出什么问题吗?index.html、Java代码和config.xml如下所示。我收到“running exec”的警报消息,但什么都没有 <html> <head> <meta charset="utf-8" /> <meta name="format-detecti
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<meta name="msapplication-tap-highlight" content="no" />
<title>PhoneGap Test App.</title>
<script type="text/javascript">
</script>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
<a onclick="runPlugin()" href="javascript:void(0);">Run Plugin</a><br>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
function runPlugin() {
alert('running exec')
exec(function(result){ alert('ok: '+result);}, function(err){ alert('Error: '+err);}, 'Echo', 'echo', ['fred']);
alert('exec has run')
}
</script>
</body>
</html>
package org.apache.cordova.plugin;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* This class echoes a string called from JavaScript.
*/
public class Echo extends CordovaPlugin {
/**
* 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);
}
}
}
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.abc" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>PhoneGapTest</name>
<description>
Phonegap app. to test Wifi.
</description>
<author email="vkuruthers@gmail.com" href="http://a.com">
</author>
<content src="index.html" />
<access origin="*" />
<plugin name="Echo" value="org.apache.cordova.plugin.Echo" />
</widget>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<meta name="msapplication-tap-highlight" content="no" />
<title>PhoneGap Test App.</title>
<script type="text/javascript">
</script>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
<a onclick="runPlugin()" href="javascript:void(0);">Run Plugin</a><br>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
function runPlugin() {
alert('running exec')
exec(function(result){ alert('ok: '+result);}, function(err){ alert('Error: '+err);}, 'Echo', 'echo', ['fred']);
alert('exec has run')
}
</script>
</body>
</html>
package org.apache.cordova.plugin;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* This class echoes a string called from JavaScript.
*/
public class Echo extends CordovaPlugin {
/**
* 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);
}
}
}
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.abc" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>PhoneGapTest</name>
<description>
Phonegap app. to test Wifi.
</description>
<author email="vkuruthers@gmail.com" href="http://a.com">
</author>
<content src="index.html" />
<access origin="*" />
<plugin name="Echo" value="org.apache.cordova.plugin.Echo" />
</widget>
电话预约
Phonegap应用程序。测试Wifi。
是否可能出现打字错误function(result){alert('ok:'+reply);}
应该是function(result){alert('ok:'+result);}
很好,我已经解决了这个问题。但是看起来这个插件还是没有被调用。调试PhoneGap应用程序的正确方法是什么?我能以某种方式单步进入exec吗?