# Initialization

## **Builder**

The Android MOVE SDK must be initialized by using the MoveSdk.Builder. It can be configured with different configurations. Once the configuration is passed, [`init`](/move-platform/move-sdk-1.x/sdk/api-interface/android-1/builder.md#init)must be called to initialize and retrieve an instance of the MOVE SDK. This instance can then be used to control SDK services. Check [API Interface](/move-platform/move-sdk-1.x/sdk/api-interface.md) for more details.

### Authentication

To be fetched using the given product’s API Key.

```kotlin
.authentication(auth: MoveAuth)
```

| auth | [MoveAuth](/move-platform/move-sdk-1.x/sdk/models/moveauth.md) | The user's Auth object. |
| ---- | -------------------------------------------------------------- | ----------------------- |

{% hint style="danger" %}

### SDK Authentication

Passing the authentication config is **required** for each initialization. The host app is also responsible for monitoring the auth state changes.
{% endhint %}

### Timeline detection services <a href="#dolphinsdk.builderv1.1-modeoftransportmodeoftransport" id="dolphinsdk.builderv1.1-modeoftransportmodeoftransport"></a>

```kotlin
.timelineServices(vararg modes: TimelineDetectionService)
```

| Parameter |                                                                                  | Description                                       |
| --------- | -------------------------------------------------------------------------------- | ------------------------------------------------- |
| modes     | [TimelineDetectionService](/move-platform/move-sdk-1.x/sdk/models/moveconfig.md) | The modes of transport host app require tracking. |

### Driving services <a href="#dolphinsdk.builderv1.1-drivingservicesdrivingservices" id="dolphinsdk.builderv1.1-drivingservicesdrivingservices"></a>

```kotlin
.drivingServices(vararg modes: DrivingService)
```

| Parameter |                                                                        | Description                                 |
| --------- | ---------------------------------------------------------------------- | ------------------------------------------- |
| modes     | [DrivingService](/move-platform/move-sdk-1.x/sdk/models/moveconfig.md) | Driving services host app require tracking. |

### Other services

```kotlin
.otherServices(vararg modes: OtherService)
```

| Parameter |                                                                      | Description                                |
| --------- | -------------------------------------------------------------------- | ------------------------------------------ |
| modes     | [OtherService](/move-platform/move-sdk-1.x/sdk/models/moveconfig.md) | Other services host app requires tracking. |

### Initialization listener <a href="#dolphinsdk.builderv1.1-initializationinitializationlistener" id="dolphinsdk.builderv1.1-initializationinitializationlistener"></a>

Block that gets invoked on initialization completion with error. On error, [MoveConfigurationError](/move-platform/move-sdk-1.x/sdk/models/moveconfigurationerror.md) is returned. On success, the [MoveSdkState](/move-platform/move-sdk-1.x/sdk/models/movestate.md) will change accordingly.

```kotlin
.initialization(listener: MoveInitializeListener)
```

| Parameter |                                                                                              | Description                                                                                                                                                                        |
| --------- | -------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| listener  | [InitializeListener](/move-platform/move-sdk-1.x/sdk/models/untitled.md#initialize-listener) | Block that gets invoked on initialization completion with error. On error, [MoveConfigurationError](/move-platform/move-sdk-1.x/sdk/models/moveconfigurationerror.md) is returned. |

### Auth state listener <a href="#dolphinsdk.builderv1.1-initializationinitializationlistener" id="dolphinsdk.builderv1.1-initializationinitializationlistener"></a>

Provide a block to be invoked every time [MoveAuthState](/move-platform/move-sdk-1.x/sdk/models/moveauthstate.md) changes.

```swift
fun authStateUpdateListener(callback: AuthStateUpdateListener)
```

| **Callback**            |                                                                                                                         |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| AuthStateUpdateListener | Block that gets invoked every time [MoveAuthState](/move-platform/move-sdk-1.x/sdk/models/moveauthstate.md) is updated. |

{% hint style="warning" %}

### Authentication Expiry

The host app is expected to monitor [MoveAuthState](/move-platform/move-sdk-1.x/sdk/models/moveauthstate.md) updates via`authStateUpdateListener`(Android / [iOS](/move-platform/move-sdk-1.x/sdk/api-interface/ios/services.md#set-sdk-auth-state-listener)) API and handle those changes accordingly.

Check [Authentication updates and expiry](/move-platform/move-sdk-1.x/sdk/models/moveauthstate.md#authentication-updates-and-expiry) for more details about authentication expiry and renewal.
{% endhint %}

### MoveSdk State listener <a href="#dolphinsdk.builderv1.1-sdkstatelistenersdkstatelistener" id="dolphinsdk.builderv1.1-sdkstatelistenersdkstatelistener"></a>

&#x20;Provide a block to be invoked every time[ MoveSdkState](/move-platform/move-sdk-1.x/sdk/models/movestate.md) changes.

{% hint style="warning" %}
The host app is expected to be monitoring [MoveSdkState](/move-platform/move-sdk-1.x/sdk/models/movestate.md) changes so it can start the SDK services when [MoveSdkState](/move-platform/move-sdk-1.x/sdk/models/movestate.md) is`.ready`or handle errors if occurred.
{% endhint %}

```kotlin
.sdkStateListener(listener: MoveSdkStateListener)
```

| Parameter |                                                                                                   | Description                                                                                                 |
| --------- | ------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| listener  | [MoveSdkStateListener](/move-platform/move-sdk-1.x/sdk/models/untitled.md#movesdk-state-listener) | Block gets called whenever the [MoveSdkState](/move-platform/move-sdk-1.x/sdk/models/movestate.md) changes. |

### Trip state listener

```kotlin
.tripStateListener(listener: MoveTripStateListener)
```

| Parameter |                                                                                                 | Description                                                                                                                                                                                                                                                                                                             |
| --------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| listener  | [MoveTripStateListener](/move-platform/move-sdk-1.x/sdk/models/untitled.md#trip-state-listener) | A listener where [`onTripStateChanged`](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/api-interface/android-1/pages/-MZIfp4AHvpUSOaycA60#DolphinSdk.Builderv1.1-tripstatelistenerTripstatelistener) gets called whenever the [MoveTripState](/move-platform/move-sdk-1.x/sdk/models/movetripstate.md) changes |

### Trip notifications

Passes a notification builder which is used to create a notification while on an active trip. For more information on that please check[ notification management](/move-platform/move-sdk-1.x/sdk/appendix/android/notification-managment.md).

```kotlin
.tripNotification(notification: Notification.Builder)
```

| Parameter    | Description                                        |
| ------------ | -------------------------------------------------- |
| notification | The notification builder to build the notification |

### Recognition notifications <a href="#dolphinsdk.builderv1.1-recognitionnotificationrecognitionnotifications" id="dolphinsdk.builderv1.1-recognitionnotificationrecognitionnotifications"></a>

Passes a notification  builder which is used to create notification while detecting activities, trips and more. For more information on that, please check[ notification management](/move-platform/move-sdk-1.x/sdk/appendix/android/notification-managment.md).

```kotlin
.recognitionNotification(notification: Notification.Builder)
```

| Parameter    | Description                                        |
| ------------ | -------------------------------------------------- |
| notification | The notification builder to build the notification |

### Mock locations <a href="#dolphinsdk.builderv1.1-allowmockmocklocations" id="dolphinsdk.builderv1.1-allowmockmocklocations"></a>

In Android it is possible to use simulated location by enabling it in the device developer mode.\
If you want the MOVE SDK to support those locations, you need to specify it. By default this is disabled to prevent wrong data.&#x20;

{% hint style="warning" %}
Points of Interests are not supported with mock locations.\
Keep in mind that mock locations may have negative impact on trip recognition afterwards.
{% endhint %}

{% hint style="info" %}
Rooted devices are still able to send mock locations without allowing mock locations.
{% endhint %}

```kotlin
.allowMockLocations(allow: Boolean)
```

| Parameter | Description                                                                  |
| --------- | ---------------------------------------------------------------------------- |
| allow     | Allows driving with mock locations. Should only be used in debug/test builds |

### Metadata <a href="#dolphinsdk.builderv1.2-metadatametadata" id="dolphinsdk.builderv1.2-metadatametadata"></a>

Host apps can use this API to add any app-level information (for ex. bluetooth beacon detected, foreground/background time, etc) to append to a trip as metadata. This metadata will be forwarded back along with the trip when fetched by the client-server, so the host app can utilize it in its app. Note: The SDK will not use this metadata element in any way, it is just passed through to the product.

The block provides the trip's start and stop times. Make sure to only include metadata events that are collected inside the given start and end periods.

```kotlin
.metadataProvider(provider: TripMetadataProvider)
```

| Parameter                                                                             | Description                                                                                                          |
| ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| [provider](/move-platform/move-sdk-1.x/sdk/models/untitled.md#trip-metadata-provider) | Callback to provide a bundle of key-value pairs to a trip. The trip is represented with a given start and stop time. |

## Initialization

Tries to initialize the SDK based on the given configuration. You can only have one initialized MoveSdk at a time. If you have a MoveSDK instance already, consider calling [`shutdown`](/move-platform/move-sdk-1.x/sdk/api-interface/android-1/android.md#shutdown-sdk)before.\
The initialization process is asynchronous and the host app is expected to register a [MoveSDKState](/move-platform/move-sdk-1.x/sdk/models/movestate.md) [`listener`](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/api-interface/android-1/pages/-MZIfp4AHvpUSOaycA60#DolphinSdk.Builderv1.1-sdkstatelistenerSdkstatelistener) to monitor successful initialization and start services when [MoveSdkState](/move-platform/move-sdk-1.x/sdk/models/movestate.md) transits to`READY` . The host app should also monitor [`initialization listener`](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/api-interface/android-1/pages/-MZIfp4AHvpUSOaycA60#DolphinSdk.Builderv1.1-initializationInitializationlistener) to handle potential [MoveConfigurationError](/move-platform/move-sdk-1.x/sdk/models/moveconfigurationerror.md).

{% hint style="warning" %}

### Application Context

Make sure to pass the application context
{% endhint %}

| Parameter | Description               |
| --------- | ------------------------- |
| context   | Main application context. |

```kotlin
fun init(context: Context): MoveSdk
```

| **Return** |                             |
| ---------- | --------------------------- |
| MoveSdk    | The instance of the MoveSdk |

| **Throws**                     |                                                                 |
| ------------------------------ | --------------------------------------------------------------- |
| MissingAuthenticationException | If the passed configuration is missing, e.g. empty access token |

{% hint style="info" %}
If you have already successfull initialized the MOVE SDK once, try to initialize the SDK next time in your application in [onCreate](https://developer.android.com/reference/android/app/Application#onCreate\(\)). This ensures that the SDK can do its work whenever the application is restarted after termination.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/api-interface/android-1/builder.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
