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.

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
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
build.gradle
dependencies {
implementation 'com.drivequant.drivekit:drivekit-core:1.7.0'
}

Make sure that you 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
MyApplication.kt
class MyApplication: Application() {
override fun onCreate() {
super.onCreate()
DriveKit.initialize(this)
}
}
MyApplication.java
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've stored your API key in a secure way in your application, you can configure DriveKit by calling the following method:

Kotlin
Java
Kotlin
DriveKit.setApiKey("MyAPIKey")
Java
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
Kotlin
DriveKit.setUserId("MyUserId")
Java
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
Kotlin
DriveKit.isConfigured()
Java
DriveKit.INSTANCE.isConfigured();

This method returns 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
Kotlin
DriveKit.reset()
Java
DriveKit.INSTANCE.reset();

All data saved locally by DriveKit will be erased.

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

Make sure that you 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
Kotlin
DriveKit.enableLogging("/path/to/my/log/directory")
Java
DriveKit.INSTANCE.enableLogging("/path/to/my/log/directory");

You can retrieve the last Uri log file by calling the following method:

Kotlin
Java
Kotlin
DriveKitLog.getLogUriFile(context)
Java
DriveKitLog.INSTANCE.getLogUriFile(context)

If your device version is on Android 10 or below, you can directly find the log file in Android/data/<your-app-package-name>/files/<path-to-my-log-directory>

If your device version is on Android 11 and if you have The Permissions Utils component on your app, you can get the log file by clicking on "Contact support" and change the email receiver. The file will be in attachment of the email.

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
Kotlin
DriveKit.disableLogging()
Java
DriveKit.INSTANCE.disableLogging();