Commit 6099e4b8 authored by Chris Scott's avatar Chris Scott

Keep track of 'enabled' state in Settings -- when using autoStart, only start...

Keep track of 'enabled' state in Settings -- when using autoStart, only start when plugin is enabled
parent a4b1ccc2
......@@ -60,19 +60,15 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
Log.d(TAG, "execute / action : " + action);
Activity activity = this.cordova.getActivity();
Boolean result = false;
if (ACTION_START.equalsIgnoreCase(action) && !isEnabled) {
result = true;
isEnabled = true;
if (!BackgroundGeolocationService.isInstanceCreated()) {
activity.startService(backgroundServiceIntent);
}
this.setEnabled(true);
callbackContext.success();
} else if (ACTION_STOP.equalsIgnoreCase(action)) {
result = true;
isEnabled = false;
activity.stopService(backgroundServiceIntent);
this.setEnabled(false);
callbackContext.success();
} else if (ACTION_CONFIGURE.equalsIgnoreCase(action)) {
result = applyConfig(data);
......@@ -108,6 +104,25 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
return result;
}
private void setEnabled(boolean value) {
isEnabled = value;
Activity activity = this.cordova.getActivity();
SharedPreferences settings = activity.getSharedPreferences(TAG, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("enabled", isEnabled);
editor.commit();
if (isEnabled) {
if (!BackgroundGeolocationService.isInstanceCreated()) {
activity.startService(backgroundServiceIntent);
}
} else {
activity.stopService(backgroundServiceIntent);
}
}
private boolean applyConfig(JSONArray data) {
Activity activity = this.cordova.getActivity();
......
......@@ -19,7 +19,9 @@ public class BootReceiver extends BroadcastReceiver {
SharedPreferences settings = context.getSharedPreferences(TAG, 0);
boolean startOnBoot = settings.getBoolean("startOnBoot", false);
if (!startOnBoot) {
boolean enabled = settings.getBoolean("enabled", false);
if (!startOnBoot || !enabled) {
return;
}
Log.i(TAG, "- BootReceiver booting service");
......
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