Commit 00d06e78 authored by Chris Scott's avatar Chris Scott

Merge pull request #36 from shutupwesley/master

Add ability to customize the notification title and text.
parents e1cdd55d 3c058687
......@@ -77,7 +77,9 @@ A full example could be:
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
debug: true // <-- enable this hear sounds for background-geolocation life-cycle.
debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification
notificationText: 'ENABLED' // <-- android only, customize the text of the notification
});
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
......@@ -162,6 +164,9 @@ 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 {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.
## Licence ##
......
......@@ -98,7 +98,9 @@ var app = {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
debug: true // <-- enable this hear sounds for background-geolocation life-cycle.
debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification
notificationText: 'ENABLED' // <-- android only, customize the text of the notification
});
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
......
......@@ -30,6 +30,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
private String distanceFilter = "30";
private String locationTimeout = "60";
private String isDebugging = "false";
private String notificationTitle = "Background tracking";
private String notificationText = "ENABLED";
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
Activity activity = this.cordova.getActivity();
......@@ -50,6 +52,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
updateServiceIntent.putExtra("locationTimeout", locationTimeout);
updateServiceIntent.putExtra("desiredAccuracy", desiredAccuracy);
updateServiceIntent.putExtra("isDebugging", isDebugging);
updateServiceIntent.putExtra("notificationTitle", notificationTitle);
updateServiceIntent.putExtra("notificationText", notificationText);
activity.startService(updateServiceIntent);
isEnabled = true;
......@@ -70,6 +74,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
this.locationTimeout = data.getString(4);
this.desiredAccuracy = data.getString(5);
this.isDebugging = data.getString(6);
this.notificationTitle = data.getString(7);
this.notificationText = data.getString(8);
} catch (JSONException e) {
callbackContext.error("authToken/url required as parameters: " + e.getMessage());
......
......@@ -90,6 +90,8 @@ public class LocationUpdateService extends Service implements LocationListener {
private Integer scaledDistanceFilter;
private Integer locationTimeout = 30;
private Boolean isDebugging;
private String notificationTitle = "Background checking";
private String notificationText = "ENABLED";
private ToneGenerator toneGenerator;
......@@ -172,15 +174,17 @@ public class LocationUpdateService extends Service implements LocationListener {
desiredAccuracy = Integer.parseInt(intent.getStringExtra("desiredAccuracy"));
locationTimeout = Integer.parseInt(intent.getStringExtra("locationTimeout"));
isDebugging = Boolean.parseBoolean(intent.getStringExtra("isDebugging"));
notificationTitle = intent.getStringExtra("notificationTitle");
notificationText = intent.getStringExtra("notificationText");
// Build a Notification required for running service in foreground.
Intent main = new Intent(this, BackgroundGpsPlugin.class);
main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Builder builder = new Notification.Builder(this);
builder.setContentTitle("Background tracking");
builder.setContentText("ENABLED");
builder.setContentTitle(notificationTitle);
builder.setContentText(notificationText);
builder.setSmallIcon(android.R.drawable.ic_menu_mylocation);
builder.setContentIntent(pendingIntent);
Notification notification;
......@@ -199,7 +203,9 @@ public class LocationUpdateService extends Service implements LocationListener {
Log.i(TAG, "- desiredAccuracy: " + desiredAccuracy);
Log.i(TAG, "- locationTimeout: " + locationTimeout);
Log.i(TAG, "- isDebugging: " + isDebugging);
Log.i(TAG, "- notificationTitle: " + notificationTitle);
Log.i(TAG, "- notificationText: " + notificationText);
this.setPace(false);
//We want this service to continue running until it is explicitly stopped
......
......@@ -6,14 +6,16 @@ module.exports = {
stationaryRadius = (config.stationaryRadius >= 0) ? config.stationaryRadius : 50, // meters
distanceFilter = (config.distanceFilter >= 0) ? config.distanceFilter : 500, // meters
locationTimeout = (config.locationTimeout >= 0) ? config.locationTimeout : 60, // seconds
desiredAccuracy = (config.desiredAccuracy >= 0) ? config.desiredAccuracy : 100; // meters
debug = config.debug || false;
desiredAccuracy = (config.desiredAccuracy >= 0) ? config.desiredAccuracy : 100, // meters
debug = config.debug || false,
notificationTitle = config.notificationTitle || "Background tracking",
notificationText = config.notificationText || "ENABLED";
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'configure',
[params, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]);
[params, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug, notificationTitle, notificationText]);
},
start: function(success, failure, config) {
exec(success || function() {},
......
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