Commit 37f2cd9f authored by Chris Scott's avatar Chris Scott

Merge branch 'android'

parents 50ff5a81 0658b684
...@@ -68,6 +68,8 @@ A full example could be: ...@@ -68,6 +68,8 @@ A full example could be:
// BackgroundGeoLocation is highly configurable. // BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, { bgGeo.configure(callbackFn, failureFn, {
url: 'http://only.for.android.com/update_location.json', // <-- only required for Android; ios allows javascript callbacks for your http
authToken: 'user_secret_auth_token', // <-- only required for Android; ios allows javascript callbacks for your http
desiredAccuracy: 10, desiredAccuracy: 10,
stationaryRadius: 20, stationaryRadius: 20,
distanceFilter: 30, distanceFilter: 30,
......
...@@ -90,6 +90,8 @@ var app = { ...@@ -90,6 +90,8 @@ var app = {
// BackgroundGeoLocation is highly configurable. // BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, { bgGeo.configure(callbackFn, failureFn, {
url: 'http://only.for.android.com/update_location.json', // <-- only required for Android; ios allows javascript callbacks for your http
authToken: 'user_secret_auth_token', // <-- only required for Android; ios allows javascript callbacks for your http
desiredAccuracy: 10, desiredAccuracy: 10,
stationaryRadius: 20, stationaryRadius: 20,
distanceFilter: 30, distanceFilter: 30,
......
...@@ -30,13 +30,13 @@ ...@@ -30,13 +30,13 @@
<source-file src="src/android/data/sqlite/SQLiteLocationDAO.java" target-dir="src/com/tenforwardconsulting/cordova/bgloc/data/sqlite" /> <source-file src="src/android/data/sqlite/SQLiteLocationDAO.java" target-dir="src/com/tenforwardconsulting/cordova/bgloc/data/sqlite" />
<source-file src="src/android/notification.png" target-dir="res/drawable" /> <source-file src="src/android/notification.png" target-dir="res/drawable" />
<source-file src="src/android/android-support-v4.jar" target-dir="libs" />
<config-file target="AndroidManifest.xml" parent="/manifest/application"> <config-file target="AndroidManifest.xml" parent="/manifest/application">
<service android:name="com.tenforwardconsulting.cordova.bgloc.LocationUpdateService" android:enabled="true" android:process=":remote" /> <service android:name="com.tenforwardconsulting.cordova.bgloc.LocationUpdateService" android:enabled="true" android:process=":remote" />
</config-file> </config-file>
<config-file target="AndroidManifest.xml" parent="/manifest"> <config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
......
...@@ -6,42 +6,76 @@ import org.json.JSONArray; ...@@ -6,42 +6,76 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.location.LocationManager;
import android.util.Log;
public class BackgroundGpsPlugin extends CordovaPlugin { public class BackgroundGpsPlugin extends CordovaPlugin {
public static final String ACTION_START = "start"; private static final String TAG = "BackgroundGpsPlugin";
public static final String ACTION_STOP = "stop";
public static final String ACTION_CONFIGURE = "configure"; public static final String ACTION_START = "start";
public static final String ACTION_STOP = "stop";
private String authToken; public static final String ACTION_CONFIGURE = "configure";
private String url; public static final String ACTION_SET_CONFIG = "setConfig";
@Override private Intent updateServiceIntent;
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
Activity activity = this.cordova.getActivity(); private String authToken;
Intent updateServiceIntent = new Intent(activity, LocationUpdateService.class); private String url;
if (ACTION_START.equalsIgnoreCase(action)) { private String stationaryRadius = "30";
if (authToken == null || url == null) { private String desiredAccuracy = "100";
callbackContext.error("Call configure before calling start"); private String distanceFilter = "30";
return false; private String locationTimeout = "60";
} private String isDebugging = "false";
updateServiceIntent.putExtra("authToken", authToken);
updateServiceIntent.putExtra("url", url); public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
activity.startService(updateServiceIntent); Activity activity = this.cordova.getActivity();
Boolean result = false;
} else if (ACTION_STOP.equalsIgnoreCase(action)) { updateServiceIntent = new Intent(activity, LocationUpdateService.class);
activity.stopService(updateServiceIntent); if (ACTION_START.equalsIgnoreCase(action)) {
} else if (ACTION_CONFIGURE.equalsIgnoreCase(action)) { result = true;
try { if (authToken == null || url == null) {
this.authToken = data.getString(0); callbackContext.error("Call configure before calling start");
this.url = data.getString(1); } else {
} catch (JSONException e) { callbackContext.success();
callbackContext.error("authToken/url required as parameters: " + e.getMessage()); updateServiceIntent.putExtra("authToken", authToken);
return false; updateServiceIntent.putExtra("url", url);
} updateServiceIntent.putExtra("stationaryRadius", stationaryRadius);
} updateServiceIntent.putExtra("desiredAccuracy", desiredAccuracy);
updateServiceIntent.putExtra("distanceFilter", distanceFilter);
return true; updateServiceIntent.putExtra("locationTimeout", locationTimeout);
} updateServiceIntent.putExtra("desiredAccuracy", desiredAccuracy);
updateServiceIntent.putExtra("isDebugging", isDebugging);
activity.startService(updateServiceIntent);
}
} else if (ACTION_STOP.equalsIgnoreCase(action)) {
result = true;
activity.stopService(updateServiceIntent);
callbackContext.success();
} else if (ACTION_CONFIGURE.equalsIgnoreCase(action)) {
result = true;
try {
// [authToken, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]);
this.authToken = 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);
} catch (JSONException e) {
callbackContext.error("authToken/url required as parameters: " + e.getMessage());
}
} else if (ACTION_SET_CONFIG.equalsIgnoreCase(action)) {
result = true;
// TODO reconfigure Service
callbackContext.success();
}
return result;
}
} }
This diff is collapsed.
var exec = require("cordova/exec"); var exec = require("cordova/exec");
module.exports = { module.exports = {
configure: function(success, failure, config) { configure: function(success, failure, config) {
var authToken = config.auth_token || 'BackgroundGeoLocation_auth_token', var authToken = config.authToken || 'BackgroundGeoLocation_auth_token',
url = config.url || 'BackgroundGeoLocation_url', url = config.url || 'BackgroundGeoLocation_url',
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
......
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