Android
This section describes how to integrate DriveKit into an Android mobile application.
DriveKit is developed with the Kotlin language and is compatible with Android 6.0 (API 23) and later versions.
We strongly recommend to target Android 8.0 (API 26) and later version for your app as DriveKit SDK will no longer support Android 7.x (API 24 and 25) from January 2024.
Android SDK version property | API level |
---|---|
minSdkVersion | 23 |
compileSdkVersion | 34 |
targetSdkVersion | 34 |
Please ensure that others libraries integrated in your project are compatible with these versions ; for example if you use a library to manage runtime permissions.
DriveKit uses the libraries listed below. These are minimal required versions. Check that they are compatible with your app:
Library | Version |
---|---|
Kotlin | 1.7.21 |
Gson | 2.9.0 |
Volley | 1.2.1 |
Room | 2.5.2 |
Work manager | 2.8.1 |
Play Services Location | 21.0.1 |
DriveKit uses key-value backup. If you use Auto Backup, you need to add
android:fullBackupOnly
in your Manifest.DriveKit will upgrade the Kotlin library version to
1.8.20
in the end of 2023. Make sure your application is ready for future updates by reading the Compatiblity Guide for Kotlin 1.8. DriveKit SDK is available on the 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/"
}
}
}
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.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
}
override fun onAccountDeleted(status: DeleteAccountStatus) {
// Remind to check the delete account status value
}
})
}
}
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
}
@Override
public void onAccountDeleted(@NonNull DeleteAccountStatus deleteAccountStatus) {
// Remind to check the delete account status value
}
});
}
}
All DriveKit modules include a method
initialize
that must be called in onCreate
method of your application class.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");
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.
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.
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.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");
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);
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);
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.You can delete a driver's account in DriveKit. This action deletes all the data related to the account.
The deletion can be done instantly or with delay.
- In the first case, when the method is called, the account is instantly deleted.
- In the second case, the driver has 30 days to log back into the application and reactivate his account.
To delete a driver's account, use the following method:
Kotlin
Java
DriveKit.deleteAccount(instantDeletion: Boolean = false)
DriveKit.INSTANCE.deleteAccount(boolean instantDeletion);
instantDeletion
can have 2 values: false
: Default value, allows the user to recover the deleted account by logging-in again with the same credentials. Users have 30 days starting from the day when the account was deleted.true
: Allow to delete an account instantly. The account and all the related data will be immediately deleted and no rollback is possible.
Your team needs to have the deletion feature activated to use this method. Please contact DriveQuant if you need it.
To be able to check whenever the account deletion is complete, you have to use the DriveKitListener interface.
You should restore the DriveKit API key in the
onAccountDeleted()
callback only when the status value is SUCCESS
.Last modified 10d ago