Commit c4a65d5b authored by shutupwesley's avatar shutupwesley

Add ability to customize the notification title and text.

parent 601c310b
...@@ -30,6 +30,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -30,6 +30,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
private String distanceFilter = "30"; private String distanceFilter = "30";
private String locationTimeout = "60"; private String locationTimeout = "60";
private String isDebugging = "false"; private String isDebugging = "false";
private String notificationTitle = "Background tracking";
private String notificationText = "ENABLED";
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) { public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
Activity activity = this.cordova.getActivity(); Activity activity = this.cordova.getActivity();
...@@ -50,6 +52,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -50,6 +52,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
updateServiceIntent.putExtra("locationTimeout", locationTimeout); updateServiceIntent.putExtra("locationTimeout", locationTimeout);
updateServiceIntent.putExtra("desiredAccuracy", desiredAccuracy); updateServiceIntent.putExtra("desiredAccuracy", desiredAccuracy);
updateServiceIntent.putExtra("isDebugging", isDebugging); updateServiceIntent.putExtra("isDebugging", isDebugging);
updateServiceIntent.putExtra("notificationTitle", notificationTitle);
updateServiceIntent.putExtra("notificationText", notificationText);
activity.startService(updateServiceIntent); activity.startService(updateServiceIntent);
isEnabled = true; isEnabled = true;
...@@ -70,6 +74,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -70,6 +74,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
this.locationTimeout = data.getString(4); this.locationTimeout = data.getString(4);
this.desiredAccuracy = data.getString(5); this.desiredAccuracy = data.getString(5);
this.isDebugging = data.getString(6); this.isDebugging = data.getString(6);
this.notificationTitle = data.getString(7);
this.notificationText = data.getString(8);
} catch (JSONException e) { } catch (JSONException e) {
callbackContext.error("authToken/url required as parameters: " + e.getMessage()); callbackContext.error("authToken/url required as parameters: " + e.getMessage());
......
...@@ -90,6 +90,8 @@ public class LocationUpdateService extends Service implements LocationListener { ...@@ -90,6 +90,8 @@ public class LocationUpdateService extends Service implements LocationListener {
private Integer scaledDistanceFilter; private Integer scaledDistanceFilter;
private Integer locationTimeout = 30; private Integer locationTimeout = 30;
private Boolean isDebugging; private Boolean isDebugging;
private String notificationTitle = "Background checking";
private String notificationText = "ENABLED";
private ToneGenerator toneGenerator; private ToneGenerator toneGenerator;
...@@ -172,6 +174,8 @@ public class LocationUpdateService extends Service implements LocationListener { ...@@ -172,6 +174,8 @@ public class LocationUpdateService extends Service implements LocationListener {
desiredAccuracy = Integer.parseInt(intent.getStringExtra("desiredAccuracy")); desiredAccuracy = Integer.parseInt(intent.getStringExtra("desiredAccuracy"));
locationTimeout = Integer.parseInt(intent.getStringExtra("locationTimeout")); locationTimeout = Integer.parseInt(intent.getStringExtra("locationTimeout"));
isDebugging = Boolean.parseBoolean(intent.getStringExtra("isDebugging")); isDebugging = Boolean.parseBoolean(intent.getStringExtra("isDebugging"));
notificationTitle = intent.getStringExtra("notificationTitle");
notificationText = intent.getStringExtra("notificationText");
// Build a Notification required for running service in foreground. // Build a Notification required for running service in foreground.
Intent main = new Intent(this, BackgroundGpsPlugin.class); Intent main = new Intent(this, BackgroundGpsPlugin.class);
...@@ -179,8 +183,8 @@ public class LocationUpdateService extends Service implements LocationListener { ...@@ -179,8 +183,8 @@ public class LocationUpdateService extends Service implements LocationListener {
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Builder builder = new Notification.Builder(this); Notification.Builder builder = new Notification.Builder(this);
builder.setContentTitle("Background tracking"); builder.setContentTitle(notificationTitle);
builder.setContentText("ENABLED"); builder.setContentText(notificationText);
builder.setSmallIcon(android.R.drawable.ic_menu_mylocation); builder.setSmallIcon(android.R.drawable.ic_menu_mylocation);
builder.setContentIntent(pendingIntent); builder.setContentIntent(pendingIntent);
Notification notification; Notification notification;
...@@ -199,6 +203,8 @@ public class LocationUpdateService extends Service implements LocationListener { ...@@ -199,6 +203,8 @@ public class LocationUpdateService extends Service implements LocationListener {
Log.i(TAG, "- desiredAccuracy: " + desiredAccuracy); Log.i(TAG, "- desiredAccuracy: " + desiredAccuracy);
Log.i(TAG, "- locationTimeout: " + locationTimeout); Log.i(TAG, "- locationTimeout: " + locationTimeout);
Log.i(TAG, "- isDebugging: " + isDebugging); Log.i(TAG, "- isDebugging: " + isDebugging);
Log.i(TAG, "- notificationTitle: " + notificationTitle);
Log.i(TAG, "- notificationText: " + notificationText);
this.setPace(false); this.setPace(false);
......
...@@ -6,14 +6,16 @@ module.exports = { ...@@ -6,14 +6,16 @@ module.exports = {
stationaryRadius = (config.stationaryRadius >= 0) ? config.stationaryRadius : 50, // meters stationaryRadius = (config.stationaryRadius >= 0) ? config.stationaryRadius : 50, // meters
distanceFilter = (config.distanceFilter >= 0) ? config.distanceFilter : 500, // meters distanceFilter = (config.distanceFilter >= 0) ? config.distanceFilter : 500, // meters
locationTimeout = (config.locationTimeout >= 0) ? config.locationTimeout : 60, // seconds locationTimeout = (config.locationTimeout >= 0) ? config.locationTimeout : 60, // seconds
desiredAccuracy = (config.desiredAccuracy >= 0) ? config.desiredAccuracy : 100; // meters desiredAccuracy = (config.desiredAccuracy >= 0) ? config.desiredAccuracy : 100, // meters
debug = config.debug || false; debug = config.debug || false,
notificationTitle = config.notificationTitle || "Background checking",
notificationText = config.notificationText || "ENABLED";
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeoLocation',
'configure', 'configure',
[params, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]); [params, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug, notificationTitle, notificationText]);
}, },
start: function(success, failure, config) { start: function(success, failure, config) {
exec(success || function() {}, 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