Commit 19869fe9 authored by Zachary Giles's avatar Zachary Giles

Adding the ability to give flexible headers and content type

Example in the JS code is:
        bgGeo.configure(callbackFn, failureFn, {
                        url: ‘somewhere + UUID, // <-- only required
for Android; ios allows javascript callbacks for your http
                        params: {
        // HTTP POST params sent to your server when persisting
locations.
                        },
                        headers: {
                                "Content-type":
"application/x-www-form-urlencoded",
                                "auth_uuid": UUID,
                                "auth_token": TOKEN,
                        },
                        desiredAccuracy: 10,
                        stationaryRadius: 20,
                        distanceFilter: 30,
                        debug: true // <-- enable this hear sounds for
background-geolocation life-cycle.
                        });
parent a7cecd95
......@@ -70,6 +70,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;
......@@ -161,6 +162,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();
......@@ -194,6 +196,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);
......@@ -661,8 +664,12 @@ public class LocationUpdateService extends Service implements LocationListener {
StringEntity se = new StringEntity(params.toString());
request.setEntity(se);
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
for (String headkey: headers.keys()) {
//request.setHeader("Accept", "application/json");
//request.setHeader("Content-type", "application/json");
Log.d(TAG, "Adding Header: " + headkey + " : " + headers.get(headkey));
request.setHeader(headkey, headers.get(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
......
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