Skip to content

Commit

Permalink
Add external command parameter to control overwriting not synchronize…
Browse files Browse the repository at this point in the history
…d tracks, closes #119
  • Loading branch information
bfabiszewski committed Nov 5, 2023
1 parent 66ba7cb commit 9ca8ada
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,28 @@ led | tracking | synchronization
- clicking on current track's name will show track statistics

## Automating
- μlogger may accept commands from other applications for starting or stopping its operations. To make it work you must explicitly enable this functionality in app settings ("Allow external commands" switch).
- μlogger may accept commands from other applications for starting or stopping its operations. To make it work you must explicitly enable this functionality in app settings ("Allow external commands" switch).
- commands are sent as `broadcasts` with following `intent` parameters:
- 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"` 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)
- extra:
- `command: [command name]` (string value), 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)
- `overwrite: [true|false]` (boolean value), optional parameter for `start new logger` command:
- `true` (default) to ignore not synchronized track and overwrite it with new one
- `false` to abort if creating new track would overwrite not synchronized positions
- 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`
- command line: `am broadcast -a net.fabiszewski.ulogger.intent.action.COMMAND -e "command" "start logger" net.fabiszewski.ulogger net.fabiszewski.ulogger.ExternalCommandReceiver`
- command line: `am broadcast -a net.fabiszewski.ulogger.intent.action.COMMAND --es command "start new logger" --ez overwrite false net.fabiszewski.ulogger net.fabiszewski.ulogger.ExternalCommandReceiver`

## Location permissions
Starting with Android 11, if you want to use the application without user interaction (automating, autostart on boot), it is necessary to grant application background location permission ("Allow all the time" option).
In case of automation the controlling application must also have the same background location permission granted.
In all other cases, when you start tracking from app screen, it is enough to grant "Allow only while using the app" option.

## Battery optimization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ public void onReceive(Context context, Intent intent) {
}
if (intent != null) {
String command = intent.getStringExtra("command");
Boolean overwrite = intent.getBooleanExtra("overwrite", true);
if (command != null) {
switch (command) {
case START_LOGGER -> startLoggerService(context);
case START_NEW_LOGGER -> startNewLoggerService(context);
case START_NEW_LOGGER -> startNewLoggerService(context, overwrite);
case STOP_LOGGER -> stopLogger(context);
case START_UPLOAD -> uploadData(context);
}
Expand All @@ -48,10 +49,12 @@ public void onReceive(Context context, Intent intent) {
* Start logger service forcing new track
* @param context Context
*/
private void startNewLoggerService(Context context) {
DbAccess.newTrack(context, AutoNamePreference.getAutoTrackName(context));
Intent intent = new Intent(context, LoggerService.class);
ContextCompat.startForegroundService(context, intent);
private void startNewLoggerService(Context context, Boolean overwrite) {
if (overwrite || !DbAccess.needsSync(context)) {
DbAccess.newTrack(context, AutoNamePreference.getAutoTrackName(context));
Intent intent = new Intent(context, LoggerService.class);
ContextCompat.startForegroundService(context, intent);
}
}

/**
Expand Down

0 comments on commit 9ca8ada

Please sign in to comment.