Nathi gugan
unread,Feb 23, 2012, 7:43:41 AM2/23/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to phonegap
I have created plugin for background service (to run the application
in background) in phonegap.
here is my java code for plugin:
public class BackgroundService extends Plugin {
@Override
public PluginResult execute(String action, JSONArray args,
String callbackId)
{
PluginResult.Status status = PluginResult.Status.OK;
String result = "";
try {
if (action.equals("onCreate")) {
this.onCreate();
}
else if (action.equals("onBind")) {
Intent intent = null;
this.onBind(intent);
}
else if (action.equals("onDestroy")) {
this.onDestroy();
}
else if (action.equals("onStart")) {
Intent intent = null;
this.onStart(intent,args.getInt(1));
}
else if (action.equals("onUnbind")) {
Intent intent = null;
this.onUnbind(intent);
}
return new PluginResult(status, result);
} catch(JSONException e) {
return new
PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
public void onCreate() {
// TODO Auto-generated method stub
}
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
}
public boolean onUnbind(Intent intent) {
// TODO Auto-generated method stub
}
public void onPause()
{
super.webView.loadUrl("javascript:navigator.BackgroundService.onBackground();");
}
public void onResume()
{
super.webView.loadUrl("javascript:navigator.BackgroundService.onForeground();");
}
}
and my js file is:
function BackgroundService() {
};
BackgroundService.prototype.create = function() {
PhoneGap.exec(null, null, "BackgroundService", "onCreate",
[]);
};
BackgroundService.prototype.destroy = function() {
PhoneGap.exec(null, null, "BackgroundService", "onDestroy",
[]);
};
BackgroundService.prototype.start = function(intent,startId) {
PhoneGap.exec(null, null, "BackgroundService", "onStart",
[intent,startId]);
};
BackgroundService.prototype.bind = function(intent) {
PhoneGap.exec(null, null, "BackgroundService", "onBind",
[intent]);
};
BackgroundService.prototype.unbind = function(intent) {
PhoneGap.exec(null, null, "BackgroundService", "onUnbind",
[intent]);
};
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin("BackgroundService", new
BackgroundService());
});
and in my index.html. I have added the below code in my button click
navigator.BackgroundService.onCreate();
navigator.BackgroundService.onStart(intent,1);
But I am getting the error.please tell me where I am wrong,please
guide me,thanks in advance.