I am trying to get the location of device in a regular inteval of 10 or 20 seconds even in the the background. The background service is not working in android. I have followed the link
https://github.com/Red-Folder/Cordova-Plugin-BackgroundService/blob/master/2.9.0/README.md
I am using cordova 2.9.0. My code is for background service is
var myService = cordova.require('cordova/plugin/myService');
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
getStatus();
}
function handleSuccess(data) {
updateView(data);
}
function handleError(data) {
updateView(data);
}
function getStatus()
{
startService();
myService.getStatus(function(r){handleSuccess(r)},
function(e){handleError(e)});
};
function startService()
{
myService.startService( function(r){handleSuccess(r)},
function(e){handleError(e)});
}
function updateView(data)
{
var myVar;
if (data.ServiceRunning)
{
var options = { enableHighAccuracy: true };
myVar = setInterval(function()
{
console.log("running");
navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
}, 10000);
}
else
{
clearInterval(myVar);
}
}
function stopService() {
myService.stopService(function(r){handleSuccess(r)},
function(e){handleError(e)});
}
In the onSuccess method i have saved the location in a file. Now it is working fine with the app opening but not working in the background.