Commit a8e64698 authored by elfantin's avatar elfantin Committed by Bartek Fabiszewski
Browse files

Update ExternalCommandReceiver.java (#63)

Add external command "start new logger"
parent b7d03627
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -40,7 +40,11 @@ led | tracking | synchronization
  - target package: `net.fabiszewski.ulogger`
  - target class: `net.fabiszewski.ulogger.ExternalCommandReceiver`
  - action: `net.fabiszewski.ulogger.intent.action.COMMAND`
  - extra: `"command": [command name]`, where command name is one of: `"start logger"`, `"stop logger"`, `"start upload"`, for starting and stopping position logging and starting track data upload to server (in case live tracking is off)
  - extra: `"command": [command name]`, where command name is one of: 
    - `"start logger"` for starting position logging
    - `"start new logger"` for creating a New Track and starting position logging to it 
    - `"stop logger"` for stopping position logging
    - `"start upload"` for starting track data upload to server (in case live tracking is off)
- third party examples:
  - Automate (LlamaLab) – Send broadcast block with `Package`, `Receiver Class` and `Action` fields as above and `Extras` field eg. `{"command": "start logger"}`
  - Tasker (joaomgcd) – System → Send intent. Fields `Action`, `Package`, `Class` as above and `Extra` field eg. `command:start logger`
+18 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import androidx.preference.PreferenceManager;
public class ExternalCommandReceiver extends BroadcastReceiver {

    private static final String START_LOGGER = "start logger";
    private static final String START_NEW_LOGGER = "start new logger";
    private static final String STOP_LOGGER = "stop logger";
    private static final String START_UPLOAD = "start upload";

@@ -37,6 +38,9 @@ public class ExternalCommandReceiver extends BroadcastReceiver {
                    case START_LOGGER:
                        startLoggerService(context);
                        break;
                    case START_NEW_LOGGER:
                        startNewLoggerService(context);
                        break;
                    case STOP_LOGGER:
                        stopLogger(context);
                        break;
@@ -50,6 +54,20 @@ public class ExternalCommandReceiver extends BroadcastReceiver {
    }


    /**
     * Start logger service (new trace)
     * @param context Context
     */
    private void startNewLoggerService(Context context) {
        DbAccess db = DbAccess.getInstance();
        db.open(context);
        db.newTrack(AutoNamePreference.getAutoTrackName(context));

        db.close();
        Intent intent = new Intent(context, LoggerService.class);
        ContextCompat.startForegroundService(context, intent);
    }

    /**
     * Start logger service
     * @param context Context