Skip to content

Autoliv Datalogger Android SDK

The Android SDK is created to provide data logging functionalities to Android.

Usage

The library can be used by adding com.autoliv.datalogger:datalogger-android to the Gradle build dependencies.

Groovy

dependencies {
    implementation 'com.autoliv.datalogger:datalogger-android:0.0.2'
}

Kotlin

dependencies {
    val dataloggerVersion: String by project
    implementation("com.autoliv.datalogger:datalogger-android:${dataloggerVersion}")
}

Kotlin Code Examples

Typical sensors used for mobility are already aggregated in the MobilityDataRecorder. The LocationRequestChecker on the other hand can be used to make sure that everything is set up properly to allow recording.

A MobilityDataReader and a LocationRequestChecker can be created in an Android Activity as shown below.

import com.autoliv.datalogger.data.MobilityDataRecorder
import com.autoliv.datalogger.data.permission.LocationRequestChecker
import com.autoliv.datalogger.data.permission.LocationCheck

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val sensorManager =
            getSystemService(SENSOR_SERVICE) as SensorManager // (1)
        val locationProvider =
            LocationServices.getFusedLocationProviderClient(this) // (2)
        val locationChecker = LocationRequestChecker(
            MobilityDataRecorder.defaultLocationRequest, this
        )
        MobilityDataRecorder(sensorManager, locationProvider, "saveFolder")
    }
}
  1. This is the API that manages the sensors in Android
  2. This is the API that manages location access in Google API

To start recording, the recording settings and permissions can be checked then the result is handled by providing a callback.

import com.autoliv.datalogger.data.MobilityDataRecorder
import com.autoliv.datalogger.data.permission.LocationRequestChecker
import com.autoliv.datalogger.data.permission.LocationCheck

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        ...
        locationChecker.verify { status ->
            when (status) {
                LocationCheck.Ok -> {
                    lifecycleScope.launch { recorder.start() } // (1)
                }
                else -> { } // (2)
            }
        }
    }
}
  1. start is a suspend function so it's called under a lifecycleScope.
  2. Error handling can be done here.

To stop recording, simply calling the close method is enough

import com.autoliv.datalogger.data.MobilityDataRecorder
import com.autoliv.datalogger.data.permission.LocationRequestChecker
import com.autoliv.datalogger.data.permission.LocationCheck

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        ...
        recorder.close()
    }
}