Android

This section describes how to integrate DriveKit into an Android mobile application.

Requirements

DriveKit is developed with the Kotlin language and is compatible with Android 19 (4.4) and later versions.

The DriveKit SDK requires Google Play Services 16.0.0 or above.

Some specific feature included into the SDK such as beacon trip detection are only compatible with Android 21 (5) or later.

Integration

DriveKit repository

DriveKit SDK are available on DriveQuant Maven repository.

To access modules in the repository, add the following lines to your project build.gradle file.

build.gradle
allprojects {
repositories {
maven {
url "https://maven.drivequant.com/repository/android-sdk/"
}
}
}

Get module from repository

To add DriveKit Core module to your app add the following lines to your dependencies in your application build.gradle file.

build.gradle
dependencies {
implementation 'com.drivequant.drivekit:drivekit-core:1.1.4'
}

Be sure to always have the same version for all DriveKit modules in your project.

Initialization

DriveKit initialization

To initialize DriveKit in your app, you must call the initialization method in onCreate method of your application class.

MyApplication.kt
MyApplication.java
class MyApplication: Application() {
override fun onCreate() {
super.onCreate()
DriveKit.initialize(this)
}
}
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
DriveKit.INSTANCE.initialize(this);
}
}

All DriveKit modules include a method initialize that must be called in onCreate method of your application class.

Add API key

To use DriveKit modules, you have to obtain an API Key from DriveQuant. If you don't have an API key, please contact DriveQuant

Once you stored your API key in a secure way in your application, you can configure DriveKit by calling the following method.

Kotlin
Java
DriveKit.setApiKey("MyAPIKey")
DriveKit.INSTANCE.setApiKey("MyAPIKey");

Identify user

Each driver must be identified with a unique identifier, once you have this identifier, configure DriveKit by calling the following method.

Kotlin
Java
DriveKit.setUserId("MyUserId")
DriveKit.INSTANCE.setUserId("MyUserId");

You can call these 2 configuration methods anywhere in the code. DriveKit will save the value locally. If the app is killed and relaunched, DriveKit will be reconfigured automatically.

DriveKit SDK will not work until you set the API key and the userId

Check your configuration

You can check if DriveKit is well configured with the following method.

Kotlin
Java
DriveKit.isConfigured()
DriveKit.INSTANCE.isConfigured();

This method return true if DriveKit is well configured.

All DriveKit modules include a method called "isConfigured" that checks the minimum system requirements for each module.

Reset

If you need to reset DriveKit configuration (user logout for example), you can call the following method.

Kotlin
Java
DriveKit.reset()
DriveKit.INSTANCE.reset();

All data saved locally by DriveKit will be erased.

All DriverKit modules have reset method that erased all data saved locally by the module.

Be sure to call reset method of all modules to fully reset DriveKit configuration.

Logging

In order to facilitate the integration of the SDK into your mobile application, DriveKit provides a logging feature. To enable logging, call the following method specifying the path of the log directory.

Kotlin
Java
DriveKit.enableLogging("/path/to/my/log/directory")
DriveKit.INSTANCE.enableLogging("/path/to/my/log/directory");

One log file per month is written with the name log-<MONTH>-<YEAR>.txt (example : log-8-2019.txt). All DriveKit modules log in this file.

To use DriveKit logging features, <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> permissions must be added to AndroidManifest.xml file of the app authorize and for devices running Android 6 or later; it's required to ask the user for this permission.

Disable logging by calling:

Kotlin
Java
DriveKit.disableLogging()
DriveKit.INSTANCE.disableLogging();