PhoneGap 2.9.0插件示例

时间:2013-08-14 15:02:25

标签: java android cordova

您好我正在开发一个简单的应用程序,我需要发送一个文本到Java但我有一些问题这样做...

这是我的BackEnd

public class Echo extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    Log.e("[Connection]", "Servidor não encontrado", null);
    if (action.equals("echo")) {
        String message = args.getString(0);
        this.echo(message, callbackContext);
        return true;
    }
    return false;
}
}

我尝试在phonegap文档中做样本,但我没有运气

这是我在JS中的功能

function echo(){
alert('Passed here');//this alert is working
    cordova.exec(function(winParam) {}, function(error) {}, "Echo", "echo", ['Hi']);
};

和我的xml

<feature name="Echo">
<param name="android-package" value="net.gmlyra.Echo" />
</feature>
<!-- Deprecated plugins element. Remove in 3.0 -->
<plugins>
<plugin name="Login" value="net.gmlyra.Echo" />
</plugins>

任何人都有一个示例插件,以明确如何做到这一点?谢谢

3 个答案:

答案 0 :(得分:1)

只需更改您的JS文件&#34; Echo&#34; - &GT; &#34;登录&#34;,&#34;回声&#34; - &GT; &#34;执行&#34;并最后添加您需要的参数:// String action,JSONArray args,CallbackContext callbackContext

function echo(){
alert('Passed here');//this alert is working
    cordova.exec(function(winParam) {}, function(error) {}, "Login", "execute", [args]);
};

答案 1 :(得分:0)

cordova.exec(function(winParam) {}, function(error) {}, "Echo", "echo", ['Hi']);


cordova.exec中的Echo是服务名称,它必须与插件中的name =“Echo”相同

<plugin name="Echo" value="net.gmlyra.Echo" />

答案 2 :(得分:0)

<feature name="PushPlugin">
  <param name="ios-package" value="PushPlugin"/>

无需在插件标签上编写代码。你已经打电话了