Commit f6a27869 authored by Chris Scott's avatar Chris Scott

Merge branch 'colibri-software-master'

parents 5e1376a4 bb0a5d93
......@@ -5,16 +5,16 @@ Cross-platform background geolocation for Cordova / PhoneGap with battery-saving
Follows the [Cordova Plugin spec](https://github.com/apache/cordova-plugman/blob/master/plugin_spec.md), so that it works with [Plugman](https://github.com/apache/cordova-plugman).
This plugin leverages Cordova/PhoneGap's [require/define functionality used for plugins](http://simonmacdonald.blogspot.ca/2012/08/so-you-wanna-write-phonegap-200-android.html).
This plugin leverages Cordova/PhoneGap's [require/define functionality used for plugins](http://simonmacdonald.blogspot.ca/2012/08/so-you-wanna-write-phonegap-200-android.html).
## Using the plugin ##
The plugin creates the object `window.plugins.backgroundGeoLocation` with the methods
The plugin creates the object `window.plugins.backgroundGeoLocation` with the methods
`configure(success, fail, option)`,
`configure(success, fail, option)`,
`start(success, fail)`
`stop(success, fail)`.
`stop(success, fail)`.
## Installing the plugin ##
......@@ -66,10 +66,10 @@ A full example could be:
var failureFn = function(error) {
console.log('BackgroundGeoLocation error');
}
// BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, {
url: 'http://only.for.android.com/update_location.json', // <-- Android ONLY: your server url to send locations to
url: 'http://only.for.android.com/update_location.json', // <-- Android ONLY: your server url to send locations to
params: {
auth_token: 'user_secret_auth_token', // <-- Android ONLY: HTTP POST params sent to your server when persisting locations.
foo: 'bar' // <-- Android ONLY: HTTP POST params sent to your server when persisting locations.
......@@ -79,11 +79,12 @@ A full example could be:
},
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
distanceFilter: 30,
notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification
notificationText: 'ENABLED', // <-- android only, customize the text of the notification
activityType: 'AutomotiveNavigation',
debug: true // <-- enable this hear sounds for background-geolocation life-cycle.
debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false // <-- enable this to clear background location settings when the app terminates
});
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
......@@ -120,7 +121,7 @@ Android **WILL NOT** execute your configured ```callbackFn```. The plugin manag
### WP8
On WP8 the plugin does not support the Stationairy location and does not implement ```getStationaryLocation()``` and ```onPaceChange()```.
Keep in mind that it is **not** possible to use ```start()``` at the ```pause``` event of Cordova/PhoneGap. WP8 suspend your app immediately and ```start()``` will not be executed. So make sure you fire ```start()``` before the app is closed/minimized.
Keep in mind that it is **not** possible to use ```start()``` at the ```pause``` event of Cordova/PhoneGap. WP8 suspend your app immediately and ```start()``` will not be executed. So make sure you fire ```start()``` before the app is closed/minimized.
### Config
......@@ -181,6 +182,10 @@ Compare now background-geolocation in the scope of a city. In this image, the l
![distanceFilter at city scale](/distance-filter-city.png "distanceFilter at city scale")
#####`@param {Boolean} stopOnTerminate`
Enable this in order to force a stop() when the application terminated (e.g. on iOS, double-tap home button, swipe away the app)
### Android Config
#####`@param {String} url`
......@@ -198,8 +203,8 @@ Optional HTTP headers POSTed to your server when persisting locations
#####`@param {String} notificationText/Title`
On Android devices it is required to have a notification in the drawer because it's a "foreground service". This gives it high priority, decreasing probability of OS killing it. To customize the title and text of the notification, set these options.
#####`@param {Integer} locationTimeout
#####`@param {Integer} locationTimeout
The minimum time interval between location updates, in seconds. See [Android docs](http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(long,%20float,%20android.location.Criteria,%20android.app.PendingIntent)) for more information.
......
......@@ -20,9 +20,9 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
public static final String ACTION_SET_CONFIG = "setConfig";
private Intent updateServiceIntent;
private Boolean isEnabled = false;
private String url;
private String params;
private String headers;
......@@ -33,12 +33,13 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
private String isDebugging = "false";
private String notificationTitle = "Background tracking";
private String notificationText = "ENABLED";
private String stopOnTerminate = "false";
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
Activity activity = this.cordova.getActivity();
Boolean result = false;
updateServiceIntent = new Intent(activity, LocationUpdateService.class);
if (ACTION_START.equalsIgnoreCase(action) && !isEnabled) {
result = true;
if (params == null || headers == null || url == null) {
......@@ -56,6 +57,7 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
updateServiceIntent.putExtra("isDebugging", isDebugging);
updateServiceIntent.putExtra("notificationTitle", notificationTitle);
updateServiceIntent.putExtra("notificationText", notificationText);
updateServiceIntent.putExtra("stopOnTerminate", stopOnTerminate);
activity.startService(updateServiceIntent);
isEnabled = true;
......@@ -69,8 +71,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
result = true;
try {
// Params.
// 0 1 2 3 4 5 6 7 8 8 9
//[params, headers, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug, notificationTitle, notificationText, activityType]
// 0 1 2 3 4 5 6 7 8 9 10 11
//[params, headers, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug, notificationTitle, notificationText, activityType, stopOnTerminate]
this.params = data.getString(0);
this.headers = data.getString(1);
this.url = data.getString(2);
......@@ -81,6 +83,7 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
this.isDebugging = data.getString(7);
this.notificationTitle = data.getString(8);
this.notificationText = data.getString(9);
this.stopOnTerminate = data.getString(11);
} catch (JSONException e) {
callbackContext.error("authToken/url required as parameters: " + e.getMessage());
}
......@@ -92,4 +95,16 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
return result;
}
/**
* Override method in CordovaPlugin.
* Checks to see if it should turn off
*/
public void onDestroy() {
Activity activity = this.cordova.getActivity();
if(isEnabled && stopOnTerminate.equalsIgnoreCase("true")) {
activity.stopService(updateServiceIntent);
}
}
}
This diff is collapsed.
......@@ -23,6 +23,7 @@
- (void) getStationaryLocation:(CDVInvokedUrlCommand *)command;
- (void) onSuspend:(NSNotification *)notification;
- (void) onResume:(NSNotification *)notification;
- (void) onAppTerminate;
@end
This diff is collapsed.
......@@ -22,12 +22,13 @@ module.exports = {
notificationTitle = config.notificationTitle || "Background tracking",
notificationText = config.notificationText || "ENABLED";
activityType = config.activityType || "OTHER";
stopOnTerminate = config.stopOnTerminate || false;
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'configure',
[params, headers, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug, notificationTitle, notificationText, activityType]
[params, headers, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug, notificationTitle, notificationText, activityType, stopOnTerminate]
);
},
start: function(success, failure, config) {
......@@ -49,14 +50,14 @@ module.exports = {
failure || function() {},
'BackgroundGeoLocation',
'finish',
[]);
[]);
},
changePace: function(isMoving, success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'onPaceChange',
[isMoving]);
[isMoving]);
},
/**
* @param {Integer} stationaryRadius
......@@ -75,7 +76,7 @@ module.exports = {
/**
* Returns current stationaryLocation if available. null if not
*/
getStationaryLocation: function(success, failure) {
getStationaryLocation: function(success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
......@@ -98,7 +99,7 @@ module.exports = {
failure || function() {},
'BackgroundGeoLocation',
'addStationaryRegionListener',
[]);
[]);
},
apply: function(destination, source) {
source = source || {};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment