# Services

```dart
import 'package:movesdk/movesdk.dart';
```

## **Detection Services**

### **Start Automatic Detection**

Starts the required detection services stated in the [MoveConfig](https://docs.movesdk.com/move-platform/sdk/models/moveconfig) passed on initialization. Starting the service will set the [MoveSDKState](https://docs.movesdk.com/move-platform/sdk/models/movestate) to `.running`.

Returns false if the SDK is not in `.ready` state.

```dart
Future<bool> MoveSdk.startAutomaticDetection()
```

### **Stop Automatic Detection**

Stops the automatic detection service, including all SDK services like driving detection, points of interest, walking and places. Stopping the service will set the [MoveSDKState](https://docs.movesdk.com/move-platform/sdk/models/movestate) back to `.ready`.&#x20;

Returns false if the SDK is not in `.ready` state.

```dart
Future<bool> MoveSdk.stopAutomaticDetection()
```

### **Force Trip Recognition**

Temporarily calibrates the SDK to the highest detection mode.

In order to optimize battery consumption, the SDK goes through different detection modes with different battery consumption levels, depending on the user's current behavior and activity. In general, the SDK is responsible for alternating between those different detection modes.&#x20;

The SDK also provides hosting apps this API to call if they have their own reasons (like buttons, sensors or beacons) to believe that the user is starting a trip. This will make sure the SDK is on the highest detection state to detect the trip faster.

```dart
Future<void> MoveSdk.forceTripRecognition()
```

### **Manual Start Trip**

Manually force the start of a trip, bypassing trip validation checks. This non-standard SDK usage may be feasible only in situations where active user input can be expected. Using the metadata parameter, self-defined information can be added to each trip which can be fetched from the [timeline](https://docs.movesdk.com/move-platform/backend/move-backend/move-timeline-api#trip-metadata).

```dart
Future<bool> startTrip(Map<String, String>? metadata)
```

Returns false if the SDK is not in `.ready` state.

{% hint style="warning" %}
**Precondition**: MOVE SDK must be in`READY`[MoveSdkState](https://docs.movesdk.com/move-platform/models/movestate#flutter).

Manually starting a trip bypasses additional trip detection checks. Manually started trips must be ended with [`finishCurrentTrip()`](#finish-current-trip)`.`

It is recommended not to use [MoveOptions](https://docs.movesdk.com/move-platform/models/moveoptions#flutter) `motionPermissionMandatory` or `backgroundLocationPermissionMandatory`with this API, as they will be ignored.
{% endhint %}

### **Finish Current Trip**

Ends the current ongoing trip.

This API will end the ongoing trip and set [MoveTripState](https://docs.movesdk.com/move-platform/sdk/models/movetripstate) back to `.idle`. The SDK is responsible for detecting the trip start and end points. The SDK also provides hosting apps this API to call if they have their own reasons (like sensors or beacons) to believe that the user's trip has ended.

{% hint style="warning" %}
**Precondition**:[ MoveTripState](https://docs.movesdk.com/move-platform/sdk/models/movetripstate) should be in an active trip.
{% endhint %}

```dart
Future<void> MoveSdk.finishCurrentTrip()
```

{% hint style="info" %}
If this API is called while the user is active on a driving trip, a new trip will start again right away. If the intention is to un-track the ongoing trip, call `ignoreCurrentTrip`API.

More information about trip states can be found in [MoveTripState](https://docs.movesdk.com/move-platform/sdk/models/movetripstate).
{% endhint %}

### **Ignore Current Trip**

Ignores the current ongoing trip.&#x20;

This API will set the ongoing [MoveTripState](https://docs.movesdk.com/move-platform/sdk/models/movetripstate) to `.ignored`. Data of ignored trips is purged and not sent to the server.

{% hint style="warning" %}
**Precondition**: [MoveTripState](https://docs.movesdk.com/move-platform/sdk/models/movetripstate) should be in an active trip.
{% endhint %}

```dart
Future<void> MoveSdk.ignoreCurrentTrip()
```

## Processing Services

### **Keep in foreground (Android only)**

When an Android application is in the background it may receive limited data (location, sensors, etc.). To improve this behavior, it is possible to put the application always in the foreground with a visible notification that cannot be discarded. Just because it's visible it doesn't mean that it is performing any data collection at all. So this should not have any significant battery impact at all.

{% hint style="info" %}
Disabled by default. Since it may be annoying to the user, it should only be enabled in case of problems.
{% endhint %}

```dart
Future<void> MoveSdk.keepInForeground(bool enabled)
```

### **Keep active (Android only)**

To save battery consumption, the SDK is using several triggers to start its data listeners. In case of trouble, these triggers can be circumvented by allowing the MoveSdk to stay active all the time. In that case the SDK is always monitoring required data and is therefore consuming more battery. Depending on the configuration, it may happen that the notification (see[ notification handling](https://docs.movesdk.com/move-platform/sdk/appendix/android/notification-managment)) is always visible to the user.

{% hint style="info" %}
Disabled by default. Since this is consuming more battery, it should only be enabled in case of problems.
{% endhint %}

```dart
Future<void> MoveSdk.keepActive(bool enabled)
```

### **Get SDK State**

Gets the current[ MoveSDKState](https://docs.movesdk.com/move-platform/sdk/models/movestate);

```dart
Future<MoveState> getState() async
```

### Get Trip State

Get the current [MoveTripState](https://docs.movesdk.com/move-platform/sdk/models/movetripstate).

```dart
Future<MoveTripState> getAuthState() async
```

### Get Auth State

Get the current [MoveAuthState](https://docs.movesdk.com/move-platform/sdk/models/moveauthstate).

```dart
Future<MoveAuthState> getAuthState() async
```

### **Set SDK State Listener**

Provide a block to be invoked every time [MoveSDKState](https://docs.movesdk.com/move-platform/sdk/models/movestate) changes.

{% hint style="info" %}
Set the [MoveSDKState](https://docs.movesdk.com/move-platform/sdk/models/movestate) listener before initializing the SDK to anticipate the SDK [State](https://docs.movesdk.com/move-platform/sdk/models/movestate) changes triggered by the initialization API. \
Here the host app can start the SDK services when [MoveSDKState](https://docs.movesdk.com/move-platform/sdk/models/movestate) is`.ready`or handle errors if occurred.
{% endhint %}

```dart
Stream<MoveState> setSdkStateListener() async*
```

### **Set SDK Auth State Listener**

Provide a block to be invoked every time [MoveAuthState](https://docs.movesdk.com/move-platform/sdk/models/moveauthstate) changes.

```dart
Stream<MoveAuthState> setAuthStateListener() async*
```

{% hint style="warning" %}

### Authentication Expiry

The host app is expected to monitor [MoveAuthState](https://docs.movesdk.com/move-platform/sdk/models/moveauthstate) updates via`authStateUpdateListener` API and handle those changes accordingly.

Check [Authentication updates and expiry](https://docs.movesdk.com/move-platform/models/moveauthstate#authentication-updates-and-expiry) for more details about authentication expiry and renewal.
{% endhint %}

### **Set Trip State Listener**

Provide a block to be invoked every time [MoveTripState](https://docs.movesdk.com/move-platform/sdk/models/movetripstate) changes.

```dart
Stream<MoveTripState> setTripStateListener() async*
```

### Set Errors Listener

Provide a block to be invoked every time [MoveServiceFailure](https://docs.movesdk.com/move-platform/sdk/models/moveservicefailure) changes.

```dart
Stream<List<MoveServiceError>> setServiceErrorListener() async*
```

### Set Warnings Listener

Provide a block to be invoked every time [MoveServiceWarning](https://docs.movesdk.com/move-platform/sdk/models/moveservicewarning) changes.

```dart
Stream<List<MoveServiceWarning>> setServiceWarningListener() async*
```

### Resolve Error

Forces a permission recheck, useful for example after the motion permission request was given in iOS.

```dart
Future<void> resolveError()
```

### **Synchronize User Data**

Used to force synchronizing user data with the SDK server. Limited to once per 2 minutes.

```dart
Future<bool> synchronizeUserData()
```

Returns wether data upload is still in progress.

## Other Services

### Live Location TAG

{% hint style="info" %}
New feature since MOVE SDK 2.8.0
{% endhint %}

Adds a Tag (=string value) to trip events. This tag information is added to the timeline data.

To clear the Tag pass `null` as parameter.

After a [`shutdown(...)`](https://docs.movesdk.com/move-platform/sdk/api-interface/initialization#shutdown-sdk) the tag is also cleared.

```dart
Future<bool> setLiveLocationTag(String? tag)
```

<table data-header-hidden><thead><tr><th width="158"></th><th></th></tr></thead><tbody><tr><td><strong>Parameters</strong></td><td></td></tr><tr><td>tag</td><td>String <code>[a-z] [0-9]</code> and <code>null</code> to clear the Tag.</td></tr></tbody></table>

<table data-header-hidden><thead><tr><th width="160"></th><th></th></tr></thead><tbody><tr><td><strong>Return values</strong></td><td></td></tr><tr><td>true</td><td>Live Location Tag is applied.</td></tr><tr><td>true</td><td>Live Location Tag is cleared. (parameter <code>null</code>)</td></tr><tr><td>false</td><td>Live Location Tag exceeds the limit of 200 characters.</td></tr><tr><td>false</td><td>Live Location Tag is blank or empty.</td></tr><tr><td>false</td><td>If the passed chars are not one of these [a-z] [0-9].</td></tr></tbody></table>

### Initiate Assistance Call

*New feature in MOVE SDK 2.x; configuration in MOVE dashboard pending - please* [*get in touch*](mailto:info@dolph.in?subject=MOVE%20SDK)*.*

Initiate an assistance call to emergency services.

```dart
Future<MoveAssistanceCallStatus> initiateAssistanceCall()
```

Returns a promise with a [MoveAssistanceCallStatus](https://docs.movesdk.com/move-platform/models/moveassistancecallstatus#android).

{% hint style="warning" %}
**Precondition:** The assistance call service needs to be configured in the MOVE dashboard. The SDK needs to be in *ready* or *running* state.
{% endhint %}

### Set Assistance MetaData

```dart
Future<void> setAssistanceMetaData(String? assistanceMetadataValue)
```

<table><thead><tr><th width="281.3333333333333"></th><th width="176"></th><th></th></tr></thead><tbody><tr><td><strong>Parameters</strong></td><td></td><td></td></tr><tr><td><code>data</code></td><td><code>String</code></td><td>A string to be sent with each assistance call or impact</td></tr></tbody></table>

The metadata string is set once, and then sent to the server with each and every manual assistance call and with AID report. The contents of the string can be anything, e.g. JSON data. The assistance data is persisted once set.

### Geocode

Geo-code address lookup.

Geocode will use the system's native Geocode API or fallback to contacting the MOVE backend to attempt a geo-lookup.

```dart
Future<GeocodeResult> geocode(double latitude, double longitude) async
```

| **Parameters** |          |                         |
| -------------- | -------- | ----------------------- |
| `latitude`     | `double` | GPS location latitude.  |
| `longitude`    | `double` | GPS location longitude. |

Returns an object of type MoveGeocodeResult with either the Address as a result string, or a [MoveGeocodeError](https://docs.movesdk.com/move-platform/sdk/models/movegeocodeerror).

```dart
class MoveGeocodeResult {
  String? result;
  MoveGeocodeError? error;
}
```

{% hint style="warning" %}
**Throttle:** *Geocode* is limited to a maximum of 100 lookups per hour.

The native API may have its own throttling and maybe used up for the app calling this function.
{% endhint %}

### **Set Remote Config Change Listener**&#x20;

{% hint style="info" %}
Since MOVE SDK v2.5
{% endhint %}

Provide a block to be invoked every time [MoveConfig](https://docs.movesdk.com/move-platform/models/moveconfig#flutter) was successfully fetched from the server.

```dart
Stream<MoveConfig> setRemoteConfigChangeListener() async*
```

| **Parameters** |                                                                                                                                               |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| listener       | A callback returning a [MoveConfig](https://docs.movesdk.com/move-platform/models/moveconfig#flutter) object after a successful server fetch. |

## Device Discovery

{% hint style="danger" %}
Due to limitations in Android’s Classic Bluetooth APIs, reliable connection status tracking may not always be possible. For more details and available workarounds, see [Forcing the Signal - Classic Bluetooth](https://docs.movesdk.com/move-platform/sdk/appendix/android/forcing-the-signal-classic-bluetooth).
{% endhint %}

### Scanning Devices

Start scanning for devices which can be registered on the SDK for trip device discovery. A block will get invoked each time new devices are found.

```dart
Stream<List<MoveDevice>> startScanningDevices(
      {List<MoveDeviceFilter> filter = const [MoveDeviceFilter.paired],
      String? uuid,
      int? manufacturerId}) async*
```

<table><thead><tr><th width="208">Parameters</th><th width="194.33333333333334"></th><th></th></tr></thead><tbody><tr><td>filter</td><td>MoveDeviceFilter</td><td>Filter devices by type. See bellow.</td></tr><tr><td>uuid</td><td>string</td><td>UUID String required to scan beacons.</td></tr><tr><td>manufacturerId</td><td>int</td><td>Manufacturer ID needed to scan beacons.</td></tr></tbody></table>

Opens a stream which will receive a list of new unique devices scanned. Device scanning will be stopped when the stream is closed.

A list of filters can be specified to filter which devices to scan for:

<table><thead><tr><th width="193">MoveDeviceFilter</th><th></th></tr></thead><tbody><tr><td>paired</td><td>Scan for paired devices. <strong>Default</strong></td></tr><tr><td>connected</td><td>Show the connected devices.</td></tr><tr><td>beacon</td><td>Scan for beacon devices. <code>uuid</code> and <code>manufacturerId</code> required.</td></tr></tbody></table>

### Set MoveDevice Connection State Listener

{% hint style="info" %}
Since MOVE SDK v2.10.0
{% endhint %}

Set a [MoveDevice](https://docs.movesdk.com/move-platform/models/movedevice#flutter) connection state listener to be fired when the Bluetooth connection state of a previously registered [MoveDevice](https://docs.movesdk.com/move-platform/models/movedevice#flutter) has changed.

```dart
Stream<List<MoveDevice>> setDeviceStateListener() async*
```

| **Parameters**                                                                                                     |                                                                                                                                             |
| ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------- |
| listener -> [MoveDeviceStateListener](https://docs.movesdk.com/move-platform/models/listeners-callbacks#flutter-8) | A callback returning the [MoveDevice](https://docs.movesdk.com/move-platform/models/movedevice#flutter) which connection state was changed. |

### Get Registered Devices

Get a list of devices ([MoveDevice](https://docs.movesdk.com/move-platform/models/movedevice#flutter)) registered to be discovered during trips.

```dart
Future<List<MoveDevice>> getRegisteredDevices() async
```

### Register Devices

Register devices ([MoveDevice](https://docs.movesdk.com/move-platform/models/movedevice#flutter)) to be discovered during trips.

```dart
Future<void> registerDevices(List<MoveDevice> devices) async
```

### Register Beacon Service

Register a beacon service identifier ([MoveDevice](https://docs.movesdk.com/move-platform/models/movedevice#flutter)) to be discovered during trips.

```dart
Future<void> registerService(String uuid) async
```

### Unregister Devices

Unregister devices ([MoveDevice](https://docs.movesdk.com/move-platform/models/movedevice#flutter)) to be discovered during trips.

```dart
Future<void> unregisterDevices(List<MoveDevice> devices) async
```

{% hint style="info" %}
Since MOVE SDK v2.13: Devices are persisted after [shutdown](https://docs.movesdk.com/move-platform/sdk/api-interface/initialization#shutdown-sdk).
{% endhint %}

### Discover Devices

```dart
Stream<List<MoveScanResult>> setDeviceDiscoveryListener() async*
```

Opens a stream to receive updates when devices are scanned for during trips. See [MoveScanResult](https://docs.movesdk.com/move-platform/models/movescanresult#flutter).

### Health Listener

Opens a stream to receive updates when values of MoveHealthItems changed. See MoveHealtItem (iOS) / MoveHealthScore (Android).

```dart
Stream<List<MoveHealthItem>> setHealthListener() async*
```

### **Get Configuration**

Gets the current used Move configuration set in setup/update or configuration. If options flag `useBackendConfig` is set returns configuration set in dashboard.&#x20;

{% hint style="info" %}
Since MOVE SDK v2.16
{% endhint %}

```swift
func getMoveConfig() -> MoveConfig?
```

| **Return**                                                                 |                                                                                                        |
| -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| [MoveConfig](https://docs.movesdk.com/move-platform/sdk/models/moveconfig) | Move Configuration passed in setup/update or configuration from backend if *useBackendConfig* is set.. |

### **Step Counter**

{% hint style="info" %}
Since MOVE SDK v2.14
{% endhint %}

Should you require the Steps permission for the Health service there is a convenience function to request it:

```dart
Future<bool> requestHealthPermissions() async
```

{% hint style="warning" %}
Since MOVE SDK v2.16 HealthKit integration for is available on demand only. Contact us for support.
{% endhint %}
