Quick Start
Getting Started / Android
Setup the MOVE SDK
Code example
package com.example.movesdkandroid
import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.util.Log
import androidx.annotation.MainThread
import io.dolphin.move.DrivingService
import io.dolphin.move.MoveAuth
import io.dolphin.move.MoveAuthState
import io.dolphin.move.MoveConfig
import io.dolphin.move.MoveConfigurationError
import io.dolphin.move.MoveDetectionService
import io.dolphin.move.MoveNotification
import io.dolphin.move.MoveSdk
import io.dolphin.move.WalkingService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
class MoveSDKTest: Application() {
override fun onCreate() {
// init the MOVE SDK
MoveSdk.init(this)
super.onCreate()
setupSdk()
}
private fun setupSdk() = runBlocking {
// Use the stored MoveAuth of this user or fetch it from the backend.
launch(Dispatchers.IO) {
// TODO: Please replace YourStorage with your preferred secure MoveAuth storage (e.g. database, shared prefs, ...)
var moveAuthOfThisUser = YourStorage.moveAuth
if (moveAuthOfThisUser.isNullOrBlank()) {
// No MoveAuth available -> fetch it from the backend.
// Source code to fetch MoveAuth object.
// PLEASE MAKE SURE TO DO THE API REQUEST TO GET THE RESPONSE
// https://docs.movesdk.com/move-platform/backend/move-backend/move-admin-api
// Response from the API Request.
// {
// "accessToken": "string",
// "refreshToken": "string",
// "userId": "string",
// "projectId": 0
// ...
// }
moveAuthOfThisUser = MoveAuth(
projectId = projectId ?: 0L,
userId = userId ?: "",
accessToken = accessToken ?: "",
refreshToken = refreshToken ?: ""
)
}
launch(Dispatchers.Main) {
prepareAndConfigSdk(moveAuthOfThisUser)
}
}
}
// Now we can prepare the notifications, listeners and config the MOVE SDK.
@MainThread
private fun prepareAndConfigSdk(moveAuth: MoveAuth) {
val channelId = "channel-sdk"
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val sdkChannel = NotificationChannel(channelId, "Dolphin SDK", NotificationManager.IMPORTANCE_DEFAULT)
notificationManager.createNotificationChannel(sdkChannel)
// Replace strings and icons as desired.
MoveSdk.get()?.recognitionNotification(
MoveNotification(
channelId,
drawableId = R.drawable.ic_recognition_notification,
contentTitle = getString(R.string.app_name),
contentText = "Active",
showWhen = true,
)
)
MoveSdk.get()?.tripNotification(
MoveNotification(
channelId,
drawableId = R.drawable.ic_trip_notification,
contentTitle = getString(R.string.app_name),
contentText = "Driving",
showWhen = true,
)
)
// Examples of some listeners
val initListener = object : MoveSdk.InitializeListener {
override fun onError(error: MoveConfigurationError) {
Log.d("MoveConfigurationError", "onError: $error")
}
}
val authStateListener = object : MoveSdk.AuthStateUpdateListener {
// Triggers whenever the MoveAuthState changes.
override fun onAuthStateUpdate(state: MoveAuthState) {
when (state) {
is MoveAuthState.INVALID -> {
// The SDK authorization state when SDK is uninitialized.
}
else -> {
}
}
}
}
// Example of adding some notifications, register listener
// and activate MOVE SDK features.
MoveSdk.get()?.apply {
// Please make sure to handle the authentication states.
authStateUpdateListener(authStateListener)
initializationListener(initListener)
// MORE INFORMATION'S ABOUT LISTENERS
// https://docs.movesdk.com/move-platform/sdk/models/listeners-callbacks
// tripNotification(drivingNotification)
// sdkStateListener(sdkStateListener)
// tripStateListener(tripStateListener)
// initiateAssistanceCall(assistanceListener)
// recognitionNotification(recognitionNotification)
consoleLogging(true)
}
// Configuration of the MOVE SDK
val moveServices: MutableSet<MoveDetectionService> = mutableSetOf()
val drivingServices: MutableSet<DrivingService> = mutableSetOf()
drivingServices.add(DrivingService.DrivingBehaviour)
drivingServices.add(DrivingService.DistractionFreeDriving)
drivingServices.add(DrivingService.DeviceDiscovery)
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())
// Deprecated in the future
MoveSdk.get()?.setup(
auth = moveAuth,
config = moveConfig,
start = true
)
// Future approach
// private val callback = object : MoveSdk.MoveAuthCallback {
// override fun onResult(result: MoveAuthResult) {
// }
// }
//
// MoveSdk.get()?.setup(
// authCode = authCode, // received from the backend
// config = moveConfig,
// start = true,
// callback = callback
// )
}
}Last updated