Commit 92877ef5 authored by Chris Scott's avatar Chris Scott

Fix merge conflicts due to previous PR appending params

parents 00d06e78 f17d0a0a
......@@ -25,6 +25,7 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
private String url;
private String params;
private String headers;
private String stationaryRadius = "30";
private String desiredAccuracy = "100";
private String distanceFilter = "30";
......@@ -40,12 +41,13 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
if (ACTION_START.equalsIgnoreCase(action) && !isEnabled) {
result = true;
if (params == null || url == null) {
if (params == null || headers == null || url == null) {
callbackContext.error("Call configure before calling start");
} else {
callbackContext.success();
updateServiceIntent.putExtra("url", url);
updateServiceIntent.putExtra("params", params);
updateServiceIntent.putExtra("headers", headers);
updateServiceIntent.putExtra("stationaryRadius", stationaryRadius);
updateServiceIntent.putExtra("desiredAccuracy", desiredAccuracy);
updateServiceIntent.putExtra("distanceFilter", distanceFilter);
......@@ -66,17 +68,17 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
} else if (ACTION_CONFIGURE.equalsIgnoreCase(action)) {
result = true;
try {
// [params, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]);
// [params, headers url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]);
this.params = data.getString(0);
this.url = data.getString(1);
this.stationaryRadius = data.getString(2);
this.distanceFilter = data.getString(3);
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);
this.headers = data.getString(1);
this.url = data.getString(2);
this.stationaryRadius = data.getString(3);
this.distanceFilter = data.getString(4);
this.locationTimeout = data.getString(5);
this.desiredAccuracy = data.getString(6);
this.isDebugging = data.getString(7);
this.notificationTitle = data.getString(8);
this.notificationText = data.getString(9);
} catch (JSONException e) {
callbackContext.error("authToken/url required as parameters: " + e.getMessage());
}
......
package com.tenforwardconsulting.cordova.bgloc;
import java.util.List;
import java.util.Iterator;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
......@@ -70,6 +71,7 @@ public class LocationUpdateService extends Service implements LocationListener {
private long lastUpdateTime = 0l;
private JSONObject params;
private JSONObject headers;
private String url = "http://192.168.2.15:3000/users/current_location.json";
private float stationaryRadius;
......@@ -163,6 +165,7 @@ public class LocationUpdateService extends Service implements LocationListener {
if (intent != null) {
try {
params = new JSONObject(intent.getStringExtra("params"));
headers = new JSONObject(intent.getStringExtra("headers"));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
......@@ -198,6 +201,7 @@ public class LocationUpdateService extends Service implements LocationListener {
}
Log.i(TAG, "- url: " + url);
Log.i(TAG, "- params: " + params.toString());
Log.i(TAG, "- headers: " + headers.toString());
Log.i(TAG, "- stationaryRadius: " + stationaryRadius);
Log.i(TAG, "- distanceFilter: " + distanceFilter);
Log.i(TAG, "- desiredAccuracy: " + desiredAccuracy);
......@@ -669,6 +673,15 @@ public class LocationUpdateService extends Service implements LocationListener {
request.setEntity(se);
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
Iterator<String> headkeys = headers.keys();
while( headkeys.hasNext() ){
String headkey = headkeys.next();
if(headkey != null) {
Log.d(TAG, "Adding Header: " + headkey + " : " + (String)headers.getString(headkey));
request.setHeader(headkey, (String)headers.getString(headkey));
}
}
Log.d(TAG, "Posting to " + request.getURI().toString());
HttpResponse response = httpClient.execute(request);
Log.i(TAG, "Response received: " + response.getStatusLine());
......
......@@ -2,6 +2,7 @@ var exec = require("cordova/exec");
module.exports = {
configure: function(success, failure, config) {
var params = JSON.stringify(config.params || {}),
headers = JSON.stringify(config.headers || {}),
url = config.url || 'BackgroundGeoLocation_url',
stationaryRadius = (config.stationaryRadius >= 0) ? config.stationaryRadius : 50, // meters
distanceFilter = (config.distanceFilter >= 0) ? config.distanceFilter : 500, // meters
......@@ -15,7 +16,7 @@ module.exports = {
failure || function() {},
'BackgroundGeoLocation',
'configure',
[params, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug, notificationTitle, notificationText]);
[params, headers, 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