# Quick start

## Prerequisites

To complete this quickstart, make sure that your development environment meets the following requirements:

* Android Studio (latest version)
* An Android 8.0+ device with Play Services
* Your Android app must target API level 26 or higher.

Follow the steps described below in your app in order to quickly integrate the DriveKit SDK:

{% hint style="info" %}
You can also clone the following [repository](https://github.com/DriveQuantPublic/drivekit-quickstart-android), configure the required credentials then simply run the quickstart app!
{% endhint %}

## Set up your project

The DriveKit SDK is now available on the Maven Central repository starting from `2.24.0`.

## Add the TripAnalysis module to your project <a href="#docs-internal-guid-f66fad15-7fff-6cbc-8666-0a1c36fd2b31" id="docs-internal-guid-f66fad15-7fff-6cbc-8666-0a1c36fd2b31"></a>

To add the Trip Analysis module to your app, add the following line to your dependencies in your appropriate application build Gradle file:

{% tabs %}
{% tab title="build.gradle.kts" %}

```gradle
dependencies {
    implementation("com.drivequant.drivekit:drivekit-trip-analysis:$drivekit_version")
}
```

{% endtab %}

{% tab title="build.gradle" %}

```gradle
dependencies {
    implementation 'com.drivequant.drivekit:drivekit-trip-analysis:$drivekit_version'
}
```

{% endtab %}
{% endtabs %}

By adding the TripAnalysis module, it will also add the DriveKit Core module and automatically initialize the DriveKit SDK.

{% hint style="info" %}
Replace `$drivekit_version`with the latest release version of DriveKit on the [changelog](https://docs.drivequant.com/release-notes/changelog/android) page.
{% endhint %}

{% hint style="warning" %}
In some cases you may want to manually initialize the SDK. To do this you have to disable the automatic initialization. Learn more in the [Advanced configurations](https://docs.drivequant.com/get-started-drivekit/android/advanced-configurations) part.
{% endhint %}

## Configure your backup app's rules

DriveKit periodically checks for changes related to the status of permissions, sensors, as well as user disconnection. This information is included in the diagnosis log file and shared with the DriveQuant platform.

To be more accurate and capture application uninstall events, you need to allow your app to backup data.

To do this, set the `allowBackup` attribute to `true` in your Manifest project app file as shown in the following example:

{% code title="AndroidManifest.xml" %}

```xml
<manifest ... >
    ...
    <application android:allowBackup="true" ... >
        ...
    </application>
</manifest>
```

{% endcode %}

{% hint style="info" %}
By enabling backup, only DriveKit data will be backed up. If you want to back up data of your application (such as your *SharedPreferences*), you must declare your own rules in your Manifest *(see* [*https://developer.android.com/identity/data/autobackup#IncludingFiles*](https://developer.android.com/identity/data/autobackup#IncludingFiles)*)*.
{% endhint %}

All other diagnosis events (described [here](https://docs.drivequant.com/push-services/push-diagnosis-data#sample-message)) will be provided regardless of the `allowBackup` configuration.

{% hint style="warning" %}
In case of Manifest merging issue with DriveKit, please refer to the [Troubleshooting](https://docs.drivequant.com/get-started-drivekit/android/troubleshooting) page.
{% endhint %}

## Set the API key

Once you've stored your API key in a secure way in your app, configure DriveKit by calling the following method:

{% tabs %}
{% tab title="DriveKit" %}

```kotlin
fun setApiKey(key: String)
```

{% endtab %}
{% endtabs %}

## Set a user id

Each driver must be identified with a unique identifier. Once you have this identifier and you are ready to analyze trips, configure DriveKit by calling the following method:

{% tabs %}
{% tab title="DriveKit" %}

```kotlin
fun setUserId(userId: String)
```

{% endtab %}
{% endtabs %}

You can call `setApiKey()` and `setUserId()` methods anywhere in the code. DriveKit will save the value locally. If the app is killed and relaunched, DriveKit will be reconfigured automatically.

{% hint style="warning" %}
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](https://www.guidgenerator.com/online-guid-generator.aspx)) for each of your users.
{% endhint %}

{% hint style="danger" %}
DriveKit SDK will not work until you set the API key and the userId.
{% endhint %}

## Enable the autostart

The automatic mode detects vehicle movements and triggers the trip analysis without driver intervention even if the application is in background. The analysis is stopped automatically at the end of the trip.

This feature is recommended to avoid driver distraction and phone handling while driving. The automatic mode has been optimized to limit the battery drain.

By default, automatic trip detection is disabled, but you can enable it by calling the following method with the `activate` parameter to `true`:

{% tabs %}
{% tab title="DriveKitTripAnalysis" %}

```kotlin
fun activateAutoStart(activate: Boolean)
```

{% endtab %}
{% endtabs %}

## Runtime permissions

DriveKit requires some runtime permissions to be granted by the user.

To display a simple and intuitive onboarding for the user to grant these runtime permissions, add the dependency for the PermissionsUtils graphical module in your appropriate application build Gradle file:

{% tabs %}
{% tab title="build.gradle.kts" %}

```gradle
dependencies {
    implementation("com.drivequant.drivekit:drivekit-trip-analysis:$drivekit_version")
    implementation("com.drivequant.drivekit:drivekit-permissions-utils-ui:$drivekitui_version")
}
```

{% endtab %}

{% tab title="build.gradle" %}

```gradle
dependencies {
    implementation "com.drivequant.drivekit:drivekit-trip-analysis:$drivekit_version"
    implementation "com.drivequant.drivekit:drivekit-permissions-utils-ui:$drivekitui_version"
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Replace $drivekitui\_version with the latest release version of graphical modules on the [changelog](https://docs.drivequant.com/release-notes/changelog/ui-android) page.
{% endhint %}

Then, call the following code in your project:

```kotlin
PermissionsUtilsUI.showPermissionViews(context, object: PermissionViewListener {
    override fun onFinish() {
        // Code called when requested permissions are properly granted.
    }
})
```

Congratulations! You now have an app that will automatically detects every trip you will make.

## What's next?

Once your first trips are recorded, fine-tune the DriveKit SDK configuration to fit your needs:

* Configure the [Core](https://docs.drivequant.com/get-started-drivekit/android/advanced-configurations) and [TripAnalysis](https://docs.drivequant.com/trip-analysis/android) modules with advanced settings. For example, [customize the notification displayed during a trip analysis](https://docs.drivequant.com/trip-analysis/android/trip-management#configure-the-trip-notification-content),[alert the user once a trip has been analyzed by the DriveQuant servers by displaying a notification](https://docs.drivequant.com/trip-analysis/android/triplistener), activate the [crash detection](https://docs.drivequant.com/trip-analysis/android/crash-detection#principle), etc.
* Display trip-related data: provide a trip list, a timeline of driver’s score, present the user's driving habits, etc. by integrating the [Driver Data](https://docs.drivequant.com/driver-data/android/get-started) module.
* Associate each trip to a vehicle that you can configure with the [Vehicle](https://docs.drivequant.com/vehicle/android/get-started) module.
* Improve user retention by organizing [challenges](https://docs.drivequant.com/challenge), display [ranking](https://docs.drivequant.com/driver-achievement/android/get-started#get-ranking) with the community, show which [badges](https://docs.drivequant.com/driver-achievement/android/get-started#get-badges) the driver earned, etc.
