Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova scheduling task

I am developing an mobile application (platform: Android, iOS) with Cordova.

My application needs ping an URL to fetch data every hours. I want my application still ping the URL when it's closed.

I searched in google and I get some of this plugins:

  1. https://github.com/katzer/cordova-plugin-local-notifications
  2. https://github.com/katzer/cordova-plugin-background-mode

I need a plugin like the second one but also work when the application is closed like scheduled notification like the first one.

Is there any plugin like this for cordova? Or it's impossible to do background task like this with cordova.

Thank you

like image 573
Wilianto Indrawan Avatar asked Jul 20 '15 13:07

Wilianto Indrawan


1 Answers

I had some what the same issue, i needed to pick lat,lng every few minutes and calcuate the distance, but background plugin alone couldnt solve it, as it stops working when the phone goes to sleep .. so I had to make sure, the phone doesn't go to sleep ..

So i used power management plugin together with Background mode plugin.. and it works well..

Background mode Plugin: https://github.com/katzer/cordova-plugin-background-mode

Power Management Plugin https://github.com/boltex/cordova-plugin-powermanagement

if( ionic.Platform.isAndroid() ){
cordova.plugins.backgroundMode.enable();

window.powerManagement.dim(function() {
console.log('Wakelock acquired');
}, function() {
console.log('Failed to acquire wakelock');
});
window.powerManagement.setReleaseOnPause(false, function() {
console.log('setReleaseOnPause successfully');
 }, function() {
console.log('Failed to set');
 });

}
like image 147
max_code Avatar answered Oct 06 '22 12:10

max_code