Initialization

API Interface / Android

Init

The Android MOVE SDK must be initialized by adding MoveSdk.init() at the first line in your Android Application class (onCreate). This instance can then be used to control MOVE SDK services. Check API Interface for more details.

After the MOVE SDK has been initialized you also want to add notifications, listeners or activate additional features.

Also you have to configure the MOVE SDK before you are able to call .setup(...).

// your application class

override fun onCreate() {
   // init the MOVE SDK
   val moveSdk = MoveSdk.init(this)   
   
   super.onCreate()

   // Example of adding some notifications, register listener
   // and activate MOVE SDK features.
   moveSdk.apply {
     recognitionNotification(recognitionNotification)
     tripNotification(drivingNotification)
     sdkStateListener(sdkStateListener)
     tripStateListener(tripStateListener)
     authStateUpdateListener(authStateListener)
     initializationListener(initListener)
     setServiceErrorListener(errorListener)
     setServiceWarningListener(warningListener)
     initiateAssistanceCall(assistanceListener)
     consoleLogging(true)
   }
   ...
}

Config

Whenever you are ready to start the Move SDK, setup() needs to be called with a proper configuration.

   // Example of a configuration of the MOVE SDK
   val moveServices: MutableSet<MoveDetectionService> = mutableSetOf()
   
   val drivingServices: MutableSet<DrivingService> = mutableSetOf()
   drivingServices.add(DrivingService.DrivingBehaviour)
   drivingServices.add(DrivingService.DistractionFreeDriving)

   val walkingServices: MutableSet<WalkingService> = mutableSetOf()
   walkingServices.add(WalkingService.Location)

   moveServices.add(MoveDetectionService.Driving(drivingServices = drivingServices.toList()))
   moveServices.add(MoveDetectionService.Walking(walkingServices = walkingServices.toList()))
   moveServices.add(MoveDetectionService.Cycling)
   moveServices.add(MoveDetectionService.AutomaticImpactDetection)
   moveServices.add(MoveDetectionService.AssistanceCall)
   
   val moveConfig = MoveConfig(moveDetectionServices = moveServices.toList())

Setup

The data for the MoveAuth object must be fetched using the given project’s API Key (see MOVE Backend - Example request).

It is recommended to set up notifications before calling the setup() method.

It is recommended that .setup(...) is called ONLY ONCE! If .shutdown() was called then the setup process must be executed again.

.setup(
    auth: MoveAuth, 
    config: MoveConfig,
    start: Boolean?,
    motionPermissionRequired: Boolean
)

auth

The user's Auth object.

config

The move configuration

start

Boolean

motionPermissionRequired

Boolean

SDK Authentication

Passing the authentication config is required for each setup. The host app is also responsible for monitoring the AuthState changes.

Initialization listener

Block that gets invoked on initialization completion with error. On error, MoveConfigurationError is returned. On success, the MoveSdkState will change accordingly.

.initializationListener(listener: MoveInitializeListener)

Parameter

Description

listener

Block that gets invoked on initialization completion with error. On error,

Auth state listener

Provide a block to be invoked every time MoveAuthState changes.

fun authStateUpdateListener(callback: AuthStateUpdateListener)

Callback

AuthStateUpdateListener

Authentication Expiry

The host app is expected to monitor MoveAuthState updates viaauthStateUpdateListenerAPI and handle those changes accordingly.

Check Authentication updates and expiry for more details about authentication expiry and renewal.

MoveSdk State listener

Provide a block to be invoked every time MoveSdkState changes.

The host app is expected to be monitoring MoveSdkState changes so it can start the SDK services when MoveSdkState is.readyor handle errors if occurred.

.sdkStateListener(listener: MoveSdkStateListener)

Parameter

Description

listener

Trip state listener

.tripStateListener(listener: MoveTripStateListener)

Parameter

Description

listener

Trip notifications

Passes a notification builder which is used to create a notification reaching places and walking paths. For more information on that please check notification management.

.tripNotification(notification: Notification.Builder)

Parameter

Description

notification

The notification builder to build the notification

Walking notifications

Passes a notification builder which is used to create a notification for places and walking paths. For more information on that please check notification management.

.walkingNotification(notification: Notification.Builder)

Parameter

Description

notification

The notification builder to build the notification

Recognition notifications

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.

.recognitionNotification(notification: Notification.Builder)

Parameter

Description

notification

The notification builder to build the notification

Mock locations

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.

Points of Interests are not supported with mock locations. Keep in mind that mock locations may have negative impact on trip recognition afterwards.

Rooted devices are still able to send mock locations without allowing mock locations.

.allowMockLocations(allow: Boolean)

Parameter

Description

allow

Allows driving with mock locations. Should only be used in debug/test builds

Trip Metadata

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 MOVE SDK will not use this metadata element in any way, it is just passed through to the project.

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.

.metadataProvider(provider: TripMetadataProvider)

Parameter

Description

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 MOVE SDK. You can only have one initialized MOVE SDK at a time. If you have a MOVE SDK instance already, consider calling shutdownbefore. The initialization process is asynchronous and the host app is expected to register a MoveSDKState listener to monitor successful initialization and start services when MoveSdkState transits toREADY . The host app should also monitor initialization listener to handle potential MoveConfigurationError.

Application Context

Make sure to pass the application context

Parameter

Description

context

Main application context.

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

If you have already successfull initialized the MOVE SDK once, try to initialize the MOVE SDK next time in your application in onCreate. This ensures that the MOVE SDK can do its work whenever the application is restarted after termination.

Last updated

#70: add MoveSdkAndroidConfig model

Change request updated