Nathi gugan
no leída,23 feb 2012, 7:43:4123/2/12Iniciar sesión para responder al autor
Iniciar sesión para reenviar
No tienes permiso para eliminar mensajes de este grupo
Inicia sesión para denunciar el mensaje
Mostrar el mensaje original
Las direcciones de correo electrónico de este grupo son anónimas o necesitas el permiso para ver las direcciones de correo electrónico de los miembros para poder ver el mensaje original
a 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.