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 21 (5.0) and later versions.
We strongly recommend to target Android 23 (6.0) and later version for your mobile app as DriveKit SDK will no longer support Android 21 (5.0) from January 2023.
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
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:$drivekit_version'
}
Replace $drivekit_version with the DriveKit version you are using in your app

DriveKit initialization

To initialize DriveKit in your app, you must call the initialization method in onCreate method of your application class.
The initialization method requires an Application as first parameter and an optional implementation of DriveKitListener:
MyApplication.kt
MyApplication.java
class MyApplication: Application() {
override fun onCreate() {
super.onCreate()
DriveKit.initialize(application, object : DriveKitListener {
override fun onConnected() {
// Connected to DriveKit
}
override fun onDisconnected() {
// Disconnected from DriveKit
}
override fun onAuthenticationError(errorType: RequestError) {
// DriveKit authentication error
}
override fun userIdUpdateStatus(status: UpdateUserIdStatus, userId: String?) {
// DriveKit userId updated
}
})
}
}
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
DriveKit.INSTANCE.initialize(application, new DriveKitListener() {
@Override
public void onConnected() {
// Connected to DriveKit
}
@Override
public void onDisconnected() {
// Disconnected from DriveKit
}
@Override
public void onAuthenticationError(@NonNull RequestError requestError) {
// DriveKit authentication error
}
@Override
public void userIdUpdateStatus(@NonNull UpdateUserIdStatus updateUserIdStatus, @androidx.annotation.Nullable String userId) {
// DriveKit userId updated
}
});
}
}
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
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.
We recommend never using an email address or phone number to define the unique user ID. It is recommended that you set up a unique, universal and anonymous user ID. For example, you can generate a globally unique identifier (GUID) for each of your users.
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 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
DriveKit.reset()
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

DriveKit comes with a logging feature that is enabled by default. This feature allows you to quickly identify the cause of a problem. We recommend leaving the log enabled as it does not consume memory space and is useful in the support phase. However, if you don't want to use it, it can be disabled.
You can retrieve the last Uri log file by calling the following method:
Kotlin
Java
DriveKitLog.getLogUriFile(context)
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 a log file of the previous month and the current one with the method getZippedLogUriFiles(), or by clicking on “Contact support” and change the email receiver. The file will be in attachment of the email.
Disable logging by calling:
Kotlin
Java
DriveKit.disableLogging()
DriveKit.INSTANCE.disableLogging();
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");

Get user’s information

To get the user's information (first name, last name and pseudo), call the getUserInfo method. This method will retrieve and save these data locally:
Kotlin
Java
DriveKit.getUserInfo(object : GetUserInfoQueryListener {
override fun onResponse(status: UserInfoGetStatus, userInfo: UserInfo?) {
if (status == UserInfoGetStatus.SUCCESS) {
// Get user's names in userInfo object.
}
}
}, synchronizationType = SynchronizationType.DEFAULT)
DriveKit.INSTANCE.getUserInfo((remoteUserInfoGetStatus, remoteUserInfo) -> {
// do nothing
}, SynchronizationType.DEFAULT);

Update user’s information

You can add information to a user's account such as first name, last name and pseudo. These details are optional and you can choose to make the user's account anonymous. To update the user's information, you must call the updateUserInfo method :
Kotlin
Java
DriveKit.updateUserInfo(pseudo = "New_pseudo", listener = object : UpdateUserInfoQueryListener {
override fun onResponse(status: Boolean) {
if (status) {
// The pseudo has been successfully updated.
}
}
})
DriveKit.INSTANCE.updateUserInfo(null, null, "New_pseudo, listener::onUserInfoUpdated);
Or to update all information:
Kotlin
Java
DriveKit.updateUserInfo(
"New_firstname",
"New_lastname",
"New_pseudo",
object : UpdateUserInfoQueryListener {
override fun onResponse(status: Boolean) {
if (status) {
// The firstname, lastname and pseudo have been successfully updated.
}
}
})
DriveKit.INSTANCE.updateUserInfo("New_firstname", "New_lastname", "New_pseudo", listener::onUserInfoUpdated);

Update UserId

It is possible to update the userId by calling the following method:
Kotlin
Java
DriveKit.updateUserId("newUserId")
DriveKit.INSTANCE.updateUserId("newUserId")
To be able to check whenever userId got updated and catch the update status you have to use DriveKitListener listener.
Export as PDF
Copy link
Outline
Requirements
Integration
DriveKit repository
Get module from repository
DriveKit initialization
Add API key
Identify user
Check your configuration
Reset
Logging
Get user’s information
Update user’s information
Update UserId