red-folder / bgs-core Goto Github PK
View Code? Open in Web Editor NEWCore code for the Cordova Background Service
License: Other
Core code for the Cordova Background Service
License: Other
Hi,
I am developing a mobile application using cordova, android platform.
The mobile application will detect a beacon.
Currently, i installed https://github.com/katzer/cordova-plugin-local-notifications for the notification.
However, when I swipe away the app from the recent list, I would no longer receive the notification.
I then research and most of the answers as to why the notification doesnt work when the app is close (take note: its not i force close the app from setting) is due to broadcast receiver.
I found this plugin and hence would like to ask if it could be a help to the problem I am facing. If yes, what do I need to configure or make changes so that it will help me on my problem?
Thank you.
Transferred from old repository issues: Red-Folder/Cordova-Plugin-BackgroundService#19
I need to apply the same fix as I mention in this blog post (just haven't got round to it) -> http://red-folder.blogspot.co.uk/2014/05/cordova-plugins-and-thread-blocking.html
If service is run at boot before application is run then it has empty config. It is desired to load config from some persistent storage.
First, thank you for this great plugin :)
Question: I see that doWork() can be called from the timer (as scheduled) and be called manually (using runOnce). What if doWork() is currently running (assume a long process) then I call runOnce(), is it safe? Should I use synchronized() inside doWork()?
Thank you for your answer.
Hi, first of all thanks for this plugin, i am the new of phonegap, i have create app via CLI and install plugin sample: using this link: https://github.com/Red-Folder/bgs-core/wiki/Using-the-MyService-Sample
after run this app, then getting this error below,
ava.lang.RuntimeException: Unable to instantiate service com.red_folder.phonegap.plugin.backgroundservice.sample.MyService: java.lang.ClassNotFoundException: Didn't find class "com.red_folder.phonegap.plugin.backgroundservice.sample.MyService" on path: DexPathList[[zip file "/data/app/com.service.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.service.app-1, /system/lib]]
please help ASAP:
I am waiting for your reply,
thanks advance
Hi,
I'm having problem with the plugin or i i'm doing something wrong.
I installed bgs-sample so i notice two things:
1 - run perfectly app. But when i close app and open again, the option RegisterForUpdate get disabled. Why does this happens?
2 - On boot, the service doesn't start. I'm testing on android 5. I would you like to understand this part of documentation: "To allow for your service to restart after reboot, it is recommended that any configuration of your background service is stored to some form of persistent storage (see Using the configuration)." that can be found here: https://github.com/Red-Folder/bgs-core/wiki/registerForBootStart
i'm using plugin for running websocket in background service.but when i swipe away app from recent apps my websocket terminate and not working anymore.i notice that when swipe away the app, call background service onDestroy() because of my logcat show:
D/CordovaActivity(23316): CordovaActivity.onDestroy()
D/BackgroundServicePluginLogic(23316): On Destroy Start
D/BackgroundServicePluginLogic(23316): Checking for services
D/BackgroundServicePluginLogic(23316): Found services
D/BackgroundServicePluginLogic(23316): Calling service.close()
D/ServiceDetails(23316): Close called
D/ServiceDetails(23316): Removing ServiceListener
D/BackgroundService(23316): Listener removed
D/ServiceDetails(23316): Removing ServiceConnection
D/ServiceDetails(23316): Close finished
D/BackgroundServicePluginLogic(23316): On Destroy Finish
and cause of this my websocket terminated.so what can i do for this problem?
thank u in advance
How to keeping bgs-core service alive after user exit app?
I use bgs-core for update badge number (https://github.com/katzer/cordova-plugin-badge) every 3 sec.
I used bgs-core for get number from my jsonp every 3 sec. Every thing run ok if I open my app or minimize my app the badge number can update.
But when I close my app the bgs-core can't get number from my jsonp.
Please help me howto do the bgs-core can get number from my jsonp after close app.
Thank you.
Hello,
I am trying to use your plugin to track the user location in back ground service.
I added in doWork() this:
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
I am getting error:
Exception - Can't create handler inside thread that has not called Looper.prepare()
Could u please guide me how to handle this error?
I can't compile due to this missing file.
Hello Mark,
First of all thank you for developing such a great plugin.
I am trying to run the myService example at https://github.com/Red-Folder/bgs-core/wiki/Using-the-MyService-Sample .
When I run it on my device it shows two alert boxes viz . .. "undefined" and "invalid action" -- successively.
Please help me with this. Am I missing anything here ?
Thanks !
I had done all the steps as given but still I am getting class not found error. Why?
Please help me..?
First of all, i would like to express my gratitude to your tremendous effort and glamorous work. This plugin is so awesome.
I am trying to create reminder app these days, my technologies are based on,
HTML5, javascript, jquery and Phonegap 2.7.0.
I need to distribute this app among all the major mobile OS, such as Android, IOS, Windows Phone 8.
Here are my Questions;
I am very pleased to here from you.
Hello,
thank you for this wonderful plugin.
It works very well on Android 4.4 and lower.
But when I test it with Eclipse and Android 5 SDK on an Android 5.0 emulator, background service not starting.
I hope you can fix it.
Thank you very much.
Log:
10-24 14:46:58.119: D/BackgroundServicePluginLogic(1206): Start of Execute
10-24 14:46:58.120: D/BackgroundServicePluginLogic(1206): Withing try block
10-24 14:46:58.122: D/BackgroundServicePluginLogic(1206): Finding servicename com.domain.demoapp.MyService
10-24 14:46:58.122: D/BackgroundServicePluginLogic(1206): Services contain 0 records
10-24 14:46:58.123: D/BackgroundServicePluginLogic(1206): Creating new Service Details
10-24 14:46:58.132: W/PluginManager(1206): THREAD WARNING: exec() call to BackgroundServicePlugin.getStatus blocked the main thread for 231ms. Plugin should use CordovaInterface.getThreadPool().
10-24 14:47:00.176: W/PluginManager(1206): THREAD WARNING: exec() call to File.getFile blocked the main thread for 264ms. Plugin should use CordovaInterface.getThreadPool().
10-24 14:47:03.076: D/BackgroundServicePluginLogic(1206): Action = getStatus
10-24 14:47:03.211: D/BackgroundServicePlugin(1206): logicResult = com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic$ExecuteResult@389df6c2
10-24 14:47:03.251: D/BackgroundServicePlugin(1206): Start of transformResult
10-24 14:47:03.266: D/BackgroundServicePlugin(1206): Status is OK
10-24 14:47:03.267: D/BackgroundServicePlugin(1206): We have data
10-24 14:47:03.269: D/BackgroundServicePlugin(1206): End of transformResult
10-24 14:47:03.270: D/BackgroundServicePlugin(1206): pluginResult = org.apache.cordova.PluginResult@187d5cd3
10-24 14:47:03.272: D/BackgroundServicePlugin(1206): pluginResult.getMessage() = {"Success":true,"ErrorCode":0,"ErrorMessage":"","ServiceRunning":false,"RegisteredForBootStart":false,"RegisteredForUpdates":false}
10-24 14:47:03.272: D/BackgroundServicePlugin(1206): Dont keep Callback
10-24 14:47:04.200: D/BackgroundServicePluginLogic(1206): Start of Execute
10-24 14:47:04.201: D/BackgroundServicePluginLogic(1206): Withing try block
10-24 14:47:04.202: D/BackgroundServicePluginLogic(1206): Finding servicename com.domain.demoapp.MyService
10-24 14:47:04.366: D/BackgroundServicePluginLogic(1206): Services contain 1 records
10-24 14:47:04.367: D/BackgroundServicePluginLogic(1206): Found existing Service Details
10-24 14:47:04.368: D/BackgroundServicePluginLogic(1206): Action = startService
10-24 14:47:04.368: D/ServiceDetails(1206): Starting startService
10-24 14:47:04.368: D/ServiceDetails(1206): Attempting to bind to Service
10-24 14:47:04.369: D/ServiceDetails(1206): Starting bindToService
10-24 14:47:04.427: D/ServiceDetails(1206): Attempting to start service
10-24 14:47:04.632: D/ServiceDetails(1206): bindToService failed
10-24 14:47:04.632: D/ServiceDetails(1206): java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.domain.demoapp.MyService }
10-24 14:47:04.632: D/ServiceDetails(1206): at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1674)
10-24 14:47:04.632: D/ServiceDetails(1206): at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1703)
10-24 14:47:04.632: D/ServiceDetails(1206): at android.app.ContextImpl.startService(ContextImpl.java:1687)
10-24 14:47:04.632: D/ServiceDetails(1206): at android.content.ContextWrapper.startService(ContextWrapper.java:515)
10-24 14:47:04.632: D/ServiceDetails(1206): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic$ServiceDetails.bindToService(BackgroundServicePluginLogic.java:604)
10-24 14:47:04.632: D/ServiceDetails(1206): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic$ServiceDetails.startService(BackgroundServicePluginLogic.java:335)
10-24 14:47:04.632: D/ServiceDetails(1206): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic.execute(BackgroundServicePluginLogic.java:188)
10-24 14:47:04.632: D/ServiceDetails(1206): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePlugin$1.run(BackgroundServicePlugin.java:68)
10-24 14:47:04.632: D/ServiceDetails(1206): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
10-24 14:47:04.632: D/ServiceDetails(1206): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
10-24 14:47:04.632: D/ServiceDetails(1206): at java.lang.Thread.run(Thread.java:818)
10-24 14:47:04.653: D/ServiceDetails(1206): Finished bindToService
10-24 14:47:04.654: D/ServiceDetails(1206): Bind Failed
10-24 14:47:04.655: D/ServiceDetails(1206): Finished startService
10-24 14:47:04.656: D/BackgroundServicePlugin(1206): logicResult = com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic$ExecuteResult@3ddb0010
10-24 14:47:04.656: D/BackgroundServicePlugin(1206): Start of transformResult
10-24 14:47:04.656: D/BackgroundServicePlugin(1206): Status is ERROR
10-24 14:47:04.657: D/BackgroundServicePlugin(1206): We have data
10-24 14:47:04.657: D/BackgroundServicePlugin(1206): End of transformResult
10-24 14:47:04.657: D/BackgroundServicePlugin(1206): pluginResult = org.apache.cordova.PluginResult@2ca41709
10-24 14:47:04.658: D/BackgroundServicePlugin(1206): pluginResult.getMessage() = {"Success":false,"ErrorCode":-4,"ErrorMessage":"Plugin unable to bind to background service","ServiceRunning":false,"RegisteredForBootStart":false,"RegisteredForUpdates":false}
10-24 14:47:04.658: D/BackgroundServicePlugin(1206): Dont keep Callback
Hi there,
In order to make it more useful to understand for future use in bigger project I' want to migrate the current background service sample project to a MVC structure.
In the html file only html and one or more files in angularjs with the controllers,services,directives and whatever is needed.
Because I don't want to reinvent the wheel, first of all I would like to know if anybody have tried this before?
Thanks,
Guillermo
Transferred from old repo issues -> Red-Folder/Cordova-Plugin-BackgroundService#22
Hello,
I've just got a couple of questions about this plugin.
myService.enableTimer(5000, function(r){ ...etc
Thanks for the great plugin!
Hi,
ive been testing out this amazing plugin, building on the example provided, and its has been great. But ive been searching for a way to stop the service from MyService.java but unable to do it. Is there anyway that i can stop the service from the java file instead of the front-end javascript ? Thanks !
Cheers,
Darren
Hi,
I create a service named CoreService using bgs-core
I enable the timer using 'enableTimer(50 * 1000);'
The timer worked fine when the app is open.
When the app go to background, the CoreService is still running in the background, but the timer did not work.
Why you choose Timer to schedule task?
Will AlarmManager be a better chooice when CoreService running in background?
tkx
I try to call the setConfiguration method.
I receive the following error when
console.log("Error: " + data.ErrorMessage)
02-14 12:31:21.519: I/chromium(19014): [INFO:CONSOLE(50)] "Error: undefined", source: file:///android_asset/www/js/service.js (50)
02-14 12:31:21.529: I/chromium(19014): [INFO:CONSOLE(51)] "
console.log(JSON.stringify(data));
{"TimerMilliseconds":60000,"LatestResult":{},"Configuration":{},"ErrorCode":-99,"Success":false,"RegisteredForBootStart":false,"TimerEnabled":false,"ServiceRunning":true}", source: file:///android_asset/www/js/service.js (51)
Can you tell me what is the reason for the error?
Hello,
First i want to thank you for the amazing plugin!
I'm building an app which has the ability to track people, this happens in a background service. It all worked fine till now. I’m implementing onStartCommand which I need to handle 3 different intents.
What’s in the onStartCommand:
I have two notifications, one which is triggered when the user turns GPS off and one the keep the service running as long as possible (startforeground notification).
Then I have a widget which contains a button, onclick an intent is send to the service and after running runOnce an new intent is passed to the main activity.
The problem is that if i implement the onStartCommand doWork doesn’t triggers at all. I tried to remove chunks of code out of the onStartCommand but doWork only starts “doing work” when i completely remove the onStartCommand. I even logged rule by rule, but i can't figure it out. All rulles in the onstartcommand seem to work.
Do you have any idea how this can happen and how to solve it?
* edit*
When i click the widget, and run the runonce dowork works fine, that's strange,,
The onstartcommand code:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Intent Foregroundintent = new Intent(this, com.coolappz.HTML5Application.app.class);
//Foregroundintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendIntent = PendingIntent.getActivity(this, 0, Foregroundintent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(android.R.drawable.presence_offline)
.setContentTitle("app")
.setContentText("Verbinding gereed")
.setTicker("Verbinding gereed")
.setContentIntent(pendIntent);
startForeground(12, builder.build());
String gpsSwitch = intent.getStringExtra("gpsSwitch");
if("gpsChange".equals(gpsSwitch)){
isProviderEnabled();
}
String widgetButton = intent.getStringExtra("widgetButton");
if("clicked".equals(widgetButton)){
widgetAlarmTriggerd();
}
return START_REDELIVER_INTENT;
}
private void widgetAlarmTriggerd(){
Log.i("app", "In service retrived ");
widgetAlarmSwitch = true;
Intent dialogIntent = new Intent(getBaseContext(), com.coolappz.HTML5Application.app.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(dialogIntent);
runOnce();
}
private void isProviderEnabled(){
if (LocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
Toast.makeText(this, "GPS is Enabled in your device", Toast.LENGTH_SHORT).show();
notificationSwitcher = true;
notifyGpsStatus(notificationSwitcher);
}else
{
notificationSwitcher = false;
notifyGpsStatus(notificationSwitcher);
}
}
The doWork code:
@Override
protected JSONObject doWork() {
Location lastLocation = locationclient.getLastLocation();
String lastLat = Double.toString(lastLocation.getLatitude());
String lastLong = Double.toString(lastLocation.getLongitude());
JSONObject result = new JSONObject();
try {
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
String now = df.format(new Date(System.currentTimeMillis()));
if(this.LocationUpdateLong != null){
new MyAsyncTask().execute(this.LocationUpdateLong,this.LocationUpdateLat, now );
}
if(widgetAlarmSwitch){
result.put("widgetAlarm", "sendalarm");
widgetAlarmSwitch = false;
}
result.put("lat", this.LocationUpdateLat);
result.put("long", this.LocationUpdateLong);
result.put("lastLat", lastLat);
result.put("lastLong", lastLong);
result.put("date", now);
result.put("acc", this.LocationAccuracy);
} catch (JSONException e) {
Log.d(TAG, "EXCEPTION");
}
return result;
}
Hi,
i try to use your background service and follow your wiki. But i get an ErrorMessage: "Plugin unable to bind to background service".
Error Message in function displayError(){}
[Object {Success: false, ErrorCode: -4, ErrorMessage: "Plugin unable to bind to background service", ServiceRunning: false, RegisteredForBootStart: false…}
ErrorCode: -4
ErrorMessage: "Plugin unable to bind to background service"
RegisteredForBootStart: false
RegisteredForUpdates: false
ServiceRunning: false
Success: false]
That error massege i fixed with you I your solution 167a4f7.
Thx :D
Moved from old repo issue -> Red-Folder/Cordova-Plugin-BackgroundService#46
I'm having problem with this method, it does not work! I'm trying to send data from javascript to background but does not works. Please help me! Thank you!
Copied from old repo enhancement request -> Red-Folder/Cordova-Plugin-BackgroundService#36
First thank you and congratulations for having this service available
I am using their service and all is well
But when I put the device to sleep the sleep service also. I know I can be doing something wrong or missing some configuration ...
I need the service remain active even when the device sleeping
How searched all over the internet and have not found the solution I thought of the possibility of you help me
I thank your attention!
I want to wrap my android library (packed as an aar) which contains an sticky service (which is currently run even after app is shutdown/terminated in my native client apps) as a cordova plugin.
Can I use this module to achieve what I'm looking for?
I was stuck searching cordova plugin dev docs until I found this! seems promising 👍
normal behavior is that the configuration is lost?
Thanks for the amazing pulgin!!!!
After solving the setConfig problems I ran in to some problems with the getConfig method.
I don't call the setConfig from the javascript code but I can see that it is being executed.
Why?
In my cordova application enable the timer when the app is open the service run without any problem..when close the app the service never run.
cordova version 4.2 (and also tested in 3.3) and android version 4.4.2(nexus 7 device).
manifest is like:
<receiver android:name="com.red_folder.phonegap.plugin.backgroundservice.BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.example.hello.MyService" >
<intent-filter>
<action android:name="com.example.hello.MyService" />
</intent-filter>
</service>
but viewing in apps -> running apps it shows 0 process and 1 service.
Here is the logcat when close the app:
D/CordovaActivity(4246): CordovaActivity.onDestroy()
D/CordovaWebView(4246): >>> loadUrlNow()
D/BackgroundServicePluginLogic(4246): On Destroy Start
D/BackgroundServicePluginLogic(4246): Checking for services
D/BackgroundServicePluginLogic(4246): Found services
D/BackgroundServicePluginLogic(4246): Calling service.close()
D/ServiceDetails(4246): Close called
D/ServiceDetails(4246): Listener deregistering
D/ServiceDetails(4246): Listener closing
D/BackgroundServicePlugin(4246): Starting closeListener
D/BackgroundServicePlugin(4246): Sending update
D/BackgroundServicePlugin(4246): Start of transformResult
D/BackgroundServicePlugin(4246): Status is OK
D/BackgroundServicePlugin(4246): We have data
D/BackgroundServicePlugin(4246): End of transformResult
D/BackgroundServicePlugin(4246): Sent update
D/BackgroundServicePlugin(4246): Finished closeListener
D/ServiceDetails(4246): Listener closed
D/ServiceDetails(4246): Listener deregistered
D/ServiceDetails(4246): Removing ServiceListener
D/BackgroundService(4246): Listener removed
D/ServiceDetails(4246): Removing ServiceConnection
D/ServiceDetails(4246): Close finished
D/BackgroundServicePluginLogic(4246): On Destroy Finish
Is it possible to listen the network state inside the background service ?
I have to do something when the user lost or retrieve the network connection.
Any idea on how to do this ?
Thx for your time
Hi,
Is it possible to use bgs-core to spawn long running external process (native arm app bundled in cordova generated package) and keep it running forever (or until stopped by the user) using ie. doWork? I don't need to exchange any data between background service and native app, since it contains http rpc service which i'd like to utilise using cordova, so i'd like to just be sure that it's running in the background and it boots with system. Android stuff is really new to me, so if You could point me out some resources in this subject...
Kind regards
hi,
Thanks a lot for the background services plugin. I am trying to use this in one my apps and this is what I encounter when I try to build the package
/src/com/red_folder/phonegap/plugin/backgroundservice/BackgroundServicePluginLogic.java:[711,16] error: reference to put is ambiguous, both method put(String,Collection) in JSONObject and method put(String,Map) in JSONObject match
/src/com/red_folder/phonegap/plugin/backgroundservice/BackgroundServicePluginLogic.java:[712,16] error: reference to put is ambiguous, both method put(String,Collection) in JSONObject and method put(String,Map) in JSONObject match
/src/com/red_folder/phonegap/plugin/backgroundservice/BackgroundServicePluginLogic.java:[713,16] error: reference to put is ambiguous, both method put(String,Collection) in JSONObject and method put(String,Map) in JSONObject match
/src/com/red_folder/phonegap/plugin/backgroundservice/BackgroundServicePluginLogic.java:[714,16] error: reference to put is ambiguous, both method put(String,Collection) in JSONObject and method put(String,Map) in JSONObject match
I am pretty new (more like totally new) to java and if you could give me some hint on how to solve this, It'd be great.
Thanks once again for the plugin.
Note: All I mainly need is a background service that runs on Android and executes a timer event - say once 30 seconds.
Cheers,
M&M
Hi
I 'm testing, creating my own adaptation of your plugin.
The rootProject/index.html and rootProject/js/index.js files are not used anymore ?
Do I have to write all the APP in the plugin?
I do not understand that
I've follow the steps of 'build your own service" and everything works perfectly !
I use the runOnce method from javascript and as expected the doWork is called once.
In my doWork method i initialize a connection to a remote server via an Android client of Socket.IO.
But i dont understand one thing : when i close the application , the background service is still running but the socket (of socket.io in my background service) is disconnected.
In fact when the app is closing, the service restart (the runCommand method is called). Is it normal ? Is it an Android specification ?
If you want more details i can post some piece fo code.
Really nice job anyway and thx for your time.
Hi,
After restarting the phone, the service is not starting.
Please, can you help me?
Follow my file AndroidManifest.xml
Follow my file service.js
var MyBackgroundService = MyBackgroundService || {};
(function() {
"use strict";
MyBackgroundService = function() {
var _myService,
_timer = 15 * 60 * 1000; // 900000
return {
Init: function() {
try {
var serviceName = 'com.red_folder.phonegap.plugin.backgroundservice.RastreadorService',
factory = cordova.require('com.red_folder.phonegap.plugin.backgroundservice.BackgroundService');
_myService = factory.create(serviceName);
MyBackgroundService.Go();
} catch(err) {
}
},
DisplayError: function(data) {
//alert("display error");
//alert(tmz.ObjectToString(data));
},
EnableTimer: function(data) {
try {
if (data.TimerEnabled) {
//alert("service now running");
}
_myService.enableTimer(
_timer, // 900000
function(r) {
MyBackgroundService.RegisterForUpdates(r);
},
function(e) {
MyBackgroundService.DisplayError(e);
}
);
} catch(err) {
}
},
GetStatus: function() {
try {
_myService.getStatus(
function(r) {
MyBackgroundService.UpdateHandler(r);
},
function(e) {
MyBackgroundService.DisplayError(e);
}
);
} catch(err) {
}
},
Go: function() {
try {
_myService.getStatus(
function(r) {
MyBackgroundService.StartService(r);
if (!r.RegisteredForBootStart) {
MyBackgroundService.RegisterForBootStart(r);
}
}, function(e) {
MyBackgroundService.DisplayError(e);
}
);
} catch(err) {
}
},
RegisterForUpdates: function(data) {
try {
/*if (data.RegisteredForUpdates) {
return;
}*/
_myService.registerForUpdates(
function(r) {
MyBackgroundService.UpdateHandler(r);
},
function(e) {
MyBackgroundService.DisplayError(e);
}
);
} catch(err) {
}
},
DeRegisterForUpdates: function() {
try {
_myService.deregisterForUpdates(
function(r) {
MyBackgroundService.UpdateHandler(r);
},
function(e) {
MyBackgroundService.DisplayError(e);
}
);
} catch(err) {
}
},
RegisterForBootStart: function(data) {
try {
if (data.RegisteredForBootStart) {
//alert('Service started, timer enabled and service registered for Boot start');
return;
}
_myService.registerForBootStart(
function(r) {
MyBackgroundService.UpdateHandler(r);
},
function(e) {
MyBackgroundService.DisplayError(e);
}
);
} catch(err) {
}
},
DeRegisterForBootStart: function() {
try {
_myService.deregisterForBootStart(
function(r) {
MyBackgroundService.UpdateHandler(r);
},
function(e) {
MyBackgroundService.DisplayError(e);
}
);
} catch(err) {
}
},
SetConfiguration: function() {
try {
var config = {
'param1': 'p1',
'param2': 'p2'
};
_myService.setConfiguration(
config,
function(r) {
//MyBackgroundService.UpdateHandler(r);
},
function(e) {
MyBackgroundService.DisplayError(e);
}
);
} catch(err) {
}
},
StartService: function(data) {
try {
// se o serviço já estiver rodando....
if (data.ServiceRunning) {
MyBackgroundService.EnableTimer(data);
MyBackgroundService.SetConfiguration();
return;
}
_myService.startService(
function(r) {
MyBackgroundService.EnableTimer(r);
MyBackgroundService.SetConfiguration();
},
function(e) {
MyBackgroundService.DisplayError(e);
}
);
} catch(err) {
}
},
UpdateHandler: function(data) {
try {
rpBackground.getLista();
} catch(err) {
}
}
}
}();
}());
MyBackgroundService.Init()
Hi guys,
First I really appreciate this peace of code that you had developed to code in Phonegap/Android.
Is there a way to start various services that extends from the same BackgroundService ?
I have two Services, the first one start without problem, but the second one start to get weird errors after setConfiguration or enableTimer.
Thank you.
Its calling dowork native method only. I need to call javascript function(registerforupdatelisner) in background after reboot of my phone.
In 'plugin.xml' :
The actual file name is: "www/backgroundService.js"
I am using geolocation app for getting current location by phonegap. I would like to implement it in my app so that i can get user location in definite interval of time. I need to work this even if user phone restarts(switch off and switch on).But am building the phonegap aap with adobe account (uploading the .zip and downloading the apk). Am not able to implement this background plugin in my app.(not familiar with folder structure and all). Can u please explain it with an implemented example .
Note : Am using linux machine for developing .
Hope you will help me. Thank you.
Hello,
First of all thnx for the plugin, it works great, i don't really have a problem but i would like to share something with you and ask your opinion about my solution.
In my previous post on this repo i had a problem with the doWork method, it didn't run when i used onStartCommand in my backgroundservice. While I thought i solved the problem by reinstalling the plugin, it was only partly the sollution. I noticed yesterday that my backgroundservice started onboot as supposed to. But the timer didn´t start running.. Again the dowork and all the other methods didn´t get triggerd because of the onStartCommand...
So i started to digg around in the plugin and i noticed you used:
public void onStart(Intent intent, int startId) {
initialiseService();
}
If i'm correct this method is deprecated, so can't you replace this with the onStartCommand? Or use it next to the onStart method?
Because I think this is what causing my problem:
I use onStartCommand in my bachgroundservice, I need to use the annotation Overridde. In the plugin their isn't an onStartcommand (only onStart) so the initialiseService method does'nt get triggerd. Because the onStartCommand doesn't override onStart (<--guessing here).
I tested and solved this by using an onStartcommand in the plugins BackGroundService.java like this:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
initialiseService();
return START_REDELIVER_INTENT; //Could also be START_STICKY
}
and this piece of code in my backgroundservice:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
handleOnStart(intent);
Log.d("ONSTARTCOMMAND", "intent" + intent);
return START_REDELIVER_INTENT;
}
After doing this everything runs like a charm. What are your ideas on this subject?
(i'm not even close to be a JAVA pro so correct me if i'm wrong)
Greetings Mike
I'm interested in using this plugin to create a "dummy" service as described in this StackOverflow post in order to prevent a WebView from being killed (so javascript continues to execute):
http://stackoverflow.com/questions/12226703/backgrounding-phonegap-and-the-relationship-between-activity-process-and-servi
It looks like in order for the above to work, I have to use startForeground
which requires onStartCommand
. Basically my purpose for this is because I'm using Sip.JS & WebRTC to create a VoIP phone and need to be able to continue to receive calls in the background (so can't have the webview getting killed).
It looks like all I need to do is implement onStartCommand
and startForeground
to accomplish this, but I was curious if you had any additional thoughts or experience on keeping WebViews alive.
Thanks,
Lyle
Hi!
This seems like an amazing plugin but I've been my head up against a wall trying to get it installed in an Appery. I get a compiler error every time:
"/retsetere/src/com/red_folder/phonegap/plugin/backgroundservice/BackgroundServicePluginLogic.java:[710,16] error: reference to put is ambiguous, both method put(String,Collection) in JSONObject and method put(String,Map) in JSONObject match"
Maybe that I will have add everything in eclipse, but just curious if you had a quick fix?
Thanks a lot for all your hard work on this!
-Andrew
Transferred from old repo issues -> Red-Folder/Cordova-Plugin-BackgroundService#22
i followed the url: https://github.com/Red-Folder/Cordova-Plugin-BackgroundService/tree/master/3.1.0
for installation, but app not running in background.
can you explain clearly, how will i setup the package for cordova cli.
Showing error ---- Uncaught module com.red_folder.phonegap.plugin.backgroundservice.BackgroundService not found", source: file:///android_asset/www/cordova.js .
Please help me.
Thanks in advance
I want share data between Java and Javascript how do it?
Moved from old repo issue -> Red-Folder/Cordova-Plugin-BackgroundService#30
This is a known problem with KitKat. However it would help to have a hack in place to restart if stopped.
First of all thanks for the awesome plugin.
As you can see there are other developers who would really love to have a background service plugin for Phonegap Build. Will it not be possible to add this plugin as a plugin to phonegap build?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.