我为phonegap创建了一个简单的插件,但我想将一个对象作为参数而不是字符串传递,下面是我的代码结构......
BackGroundService.java
public class BackGroundService extends Plugin {
public PluginResult execute(String arg0, JSONArray args, String arg2) { //How can i pass object instead or String
}
}
worker.js
var worker = function(name, win, fail) {
PhoneGap.exec(win, win, "BackGroundService", "worker", [name]);
}
PhoneGap.addConstructor(function() {
navigator.app.addService('BackGroundService','com.service.app.BackGroundService');
})
从html调用
worker("football", win); //Pass object instead of football
var win = function(d) {
alert("success");
}
答案 0 :(得分:0)
将对象解压缩为字符串数组?
让我们假设你传递了一个名为" Sport"具有以下属性:
.name:"足球" .ball:" round" 。期间:2 .periodTiming:45
您可以将此对象解压缩到[" Football"," round",2,45],并修改您的Java代码以获取每个参数:
String name = args.getString(0);
String ball = args.getString(1);
int periods = args.getInt(2);
int timing = args.getInt(3);
HTH