---
updatedAt: 2026-05-21T09:46:04.000Z
agentTools:
  projectIndex: https://docs.damoov.com/llms.txt
---

# Setting up for Android app

First of all, you have to enable the Bluetooth OBD connection at initialization step: Check if the user's smartphone supports Bluetooth low.

## Setting up the environment

***

First of all, you have to enable the Bluetooth OBD connection at initialization step:

[block:code]
{
  "codes": [
    {
      "code": "**\n* Default Setting constructor\n* Stop tracking time is 5 minute.\n* Parking radius is 100 meters.\n* Auto start tracking is true.\n* hfOn - true if HIGH FREQUENCY data recording from sensors (acc, gyro) is ON and false otherwise.\n* isElmOn - true <- to enable bluetooth OBD connection  \n*/\nval settings = Settings(Settings.stopTrackingTimeHigh, Settings.accuracyHigh, true, true, true)\n\nTrackingApi.getInstance().initialize(this, settings)",
      "language": "kotlin"
    }
  ]
}
[/block]

**Check if the user's smartphone supports Bluetooth low energy.**

[block:callout]
{
  "type": "info",
  "title": "Bluetooth Low Energy (BLE) is required",
  "body": "Please, check whether the user's smartphone supports Bluetooth low energy. If it doesn't support BLE, you have to inform the user that his smartphone doesn't support that."
}
[/block]

[block:code]
{
  "codes": [
    {
      "code": "if (!packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {\n   // check whether the user smartphone supports BLE or not\n }",
      "language": "kotlin"
    }
  ]
}
[/block]

**Turn on Bluetooth BLE**

[block:code]
{
  "codes": [
    {
      "code": "// get Bluetooth adapter and check is it enabled or not\nval mBluetoothAdapter = BluetoothUtils.getBluetoothAdapter(this)\nmBluetoothAdapter?.let {\n    if (!mBluetoothAdapter.isEnabled) {\n        // ask user to enable Bluetooth if it's off\n        val intent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)\n        startActivityForResult(intent, Constants.REQUEST_BLUETOOTH_ENABLE_CODE)\n    } else {\n        // Bluetooth is enabled already\n    }\n}\n\n...\n\n// handle result of Bluetooth enable\noverride fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {\n    if (requestCode == Constants.REQUEST_BLUETOOTH_ENABLE_CODE && resultCode == Activity.RESULT_OK) {\n            // Bluetooth successfully enabled\n    } else {\n        // user didn't enabled Bluetooth\n    }\n    super.onActivityResult(requestCode, resultCode, data)\n}\n    ",
      "language": "kotlin"
    }
  ]
}
[/block]

## Register a callback

[block:callout]
{
  "type": "info",
  "body": "If the user's smartphone supports BLE, and you turned it on, then you can scan a Bluetooth OBD device and connect it to the telematics SDK",
  "title": "Bluetooth Low Energy (BLE) is required"
}
[/block]

All interactions with Bluetooth OBD run inside `VehicleElmManager`  You can get it by:

[block:code]
{
  "codes": [
    {
      "code": "TrackingApi.getInstance().getElmManager()",
      "language": "kotlin"
    }
  ]
}
[/block]

To receive a callback from `VehicleElmManager` you should register the `ElmLinkingListener`.
There are 4 methods inside:

* **`onScanningComplete`** - the method will be called after the device searching completed successfully. It has a list of founded devices.
* **`onScanningFailed`** - the method will be called if an error occurs during scanning Bluetooth OBD devices. The method has inside an error that you can process. Please refer to the example below.
* \*\*`onLinkingComplete` \*\*- the method will be called once the user's smartphone has been successfully paired with the Bluetooth OBD device. It returns a vehicle token and Bluetooth OBD Mac-address string.
* **`onLinkingFailed`** - the method will be called if an error occurs during the connection process.
  The method has inside an error that you can process. Please refer to the example below.

[block:code]
{
  "codes": [
    {
      "code": "\n// initialize callback\nval elmLinkingLister = object : ElmLinkingListener {\n\t\toverride fun onScanningComplete(foundDevices: List<ElmDevice>) {\n\t\t\t// choose your device from foundedDevices list\n\t\t}\n\n\t\toverride fun onScanningFailed(error: ElmLinkingError) {\n\t\t\t// error occurred during the scanning\n\t\t\twhen (error) {\n\t\t\t\tElmLinkingError.SERVER_ERROR_NETWORK_CONNECTION_NOT_AVAILABLE-> {\n\t\t\t\t\t// network error, check your connection and try again\n\t\t\t\t}\n\t\t\t\tElmLinkingError.SERVER_ERROR_UNKNOWN -> {\n\t\t\t\t\t// error on server side, try again or contact the support\n\t\t\t\t}\n\t\t\t\telse -> {\n\t\t\t\t\t// unknown error, try again\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\toverride fun onLinkingFailed(error: ElmLinkingError) {\n\t\t\t// error occurred when device was pairing with smartphone\n\t\t\twhen (error) {\n\t\t\t\tElmLinkingError.SERVER_ERROR_NETWORK_CONNECTION_NOT_AVAILABLE-> {\n\t\t\t\t\t// network error, check your connection and try again\n\t\t\t\t}\n\t\t\t\tElmLinkingError.SERVER_ERROR_UNKNOWN -> {\n\t\t\t\t\t// error on server side, try again or contact the support\n\t\t\t\t}\n\t\t\t\tElmLinkingError.VEHICLE_NOT_SUPPORTED -> {\n\t\t\t\t\t// not supported vehicle\n\t\t\t\t}\n\t\t\t\telse -> {\n\t\t\t\t\t// unknown error, try again\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\toverride fun onLinkingComplete(vehicleToken: String, elmMAC: String) {\n\t\t\t// elm device was successfully paired with vehicle.\n\t\t}\n\t}",
      "language": "kotlin"
    }
  ]
}
[/block]

As the next step, you have to register the callback

**Register callback**

[block:code]
{
  "codes": [
    {
      "code": "TrackingApi.getInstance().getElmManager()?.registerLinkingListener(elmLinkingLister)",
      "language": "kotlin"
    }
  ]
}
[/block]

[block:callout]
{
  "type": "info",
  "title": "Important",
  "body": "Don't forget to unregister the callback when it is not in use. It helps you to avoid memory leaks."
}
[/block]

**Unregister callback**

[block:code]
{
  "codes": [
    {
      "code": "TrackingApi.getInstance().getElmManager()?.unregisterLinkingListener()",
      "language": "text"
    }
  ]
}
[/block]

## Setting up the connection

***

### 1. Search Bluetooth device

Once you register the callback in `VehicleElmManager` you can start searching a Bluetooth OBD device.

[block:code]
{
  "codes": [
    {
      "code": "TrackingApi.getInstance().getElmManager()?.getElmDevices()",
      "language": "kotlin"
    }
  ]
}
[/block]

`getElmDevices` method will scan Bluetooth OBD and submit them to `onScanningComplete` method. Then, you should choose your Bluetooth OBD from the list of available devices. If something went wrong, the error will be submitted to the callback `onScanningFailed` method.

### 2. Get a vehicle

***

Make sure you have a registered vehicle. If no, please refer to [\_Vehicle management](https://docs.damoov.com/docs/vehicle-management)

[block:code]
{
  "codes": [
    {
      "code": "TrackingApi.getInstance().getElmManager()?.getVehicles()",
      "language": "text"
    }
  ]
}
[/block]

[block:callout]
{
  "type": "info",
  "title": "Important",
  "body": "You should call this method on a separate thread. \nOtherwise ```android.os.NetworkOnMainThreadException``` will be thrown"
}
[/block]

It will return an array of registered vehicles with their car tokens `Array<RegisteredVehicle>`

### 3. Connect Bluetooth OBD to the vehicle (from the step above)

Choose your vehicle from the list and register the Bluetooth OBD from step 1 with the vehicle from step 2.

[block:code]
{
  "codes": [
    {
      "code": "TrackingApi.getInstance().getElmManager()?.connectAndRegisterDevice(device.deviceMacAddress!!, selectedCar.token)",
      "language": "kotlin"
    }
  ]
}
[/block]

You should pass two parameters to `connectAndRegisterDevice` method:

* ELM-device mac-Address (`String`)
* Car token (`String`)
  The method will pair the Bluetooth OBD with your car and submit the result to the callback `onLinkingComplete` method. If something went wrong, an error will be submitted to `onLinkingFailed` method.

### Get connection status

[block:code]
{
  "codes": [
    {
      "code": "TrackingApi.getInstance().getElmManager()?.getLastSession()?.let { info: Pair<Boolean, Long> ->\n   // handle result\n}",
      "language": "kotlin"
    }
  ]
}
[/block]

It has inside a `Pair<Boolean, Long>` where:

* **first** - `Boolean` flag about is ELM-connected
* **second** - `Long` is a UNIX-timestamp when Bluetooth OBD device was connected