Telematics SDK | Developer portal
  • Get started
  • 4 Steps to Integrate SDK
  • Product Wiki
  • License
  • FAQ
  • PRODUCT DESCRIPTION
    • How it works
    • SDK Features
    • Scoring
      • Risk driving Scoring
        • Event detection
        • Trip rating
        • Overall scoring
      • Eco Scoring
    • Dataset
      • Dataset | User statistics API
      • Data samples
        • Summary - Processed track details (Rich track details)
        • Processed track waypoints (Rich track points)
        • Summary - list of Processed tracks
        • Incoming track events
        • Incoming track points (waypoints)
        • Summary - list of Incoming tracks
      • Dataset Decription
        • Bluetooth OBD - Vehicle Dataset
        • LastKnownPoints
        • IncomingTrackPoints
        • IncomingTrackEvents
        • Enriched telematics data
          • RichTracks
          • RichTrackPoints
          • RichTrackEvents
          • RichTrackDetails
          • UserStatisticDrivingDetails
        • Raw telematics data from SDK
    • Reporting
      • Drivecoins summary
      • Trip summary
      • Scoring summary
      • User state
      • Fraud
      • Trip waypoints
      • Trip events
    • External Articles
      • Why mobile telematics hits hardware telematics
  • Step 1: Create Datahub Account
  • Step 2: SDK Installation
    • Get started
    • iOS SDK installation
      • *Set up Your Development Environment
      • *Configure Your Project
      • *App Delegate
      • *Configure Framework
      • *React Native Installation
        • Create the iOS bridge
      • Add list of trips to your ViewController
      • Add statistics data to your ViewController
      • *What’s different in iOS 13?
      • *iOS 13 Permissions Wizard
      • *SDK Enable \ Disable \ Disable With Upload
      • *Incoming Tags
      • *Tracking Status
      • *SDK Delegates
      • *SDK Modes
      • *Using the Debugging Tools in Simulator
    • Android SDK installation
      • *Getting started
        • *Set up Your Development Environment
        • *Setup and enable SDK
        • *Permissions wizard
        • *Permissions dialog
        • *Configure SDK variables for notifications
      • *Subscribe to tracking events
      • *Incoming tags managing
      • *Migration from SDK v1.6.x to SDK v2.0.x
    • *Check SDK Installation
      • iOS Simulator
      • DataTool
      • ZenRoad
    • *Demo Applications
      • iOS | Open Source Demo Application
      • iOS | SDK Demo Application
      • iOS | Swift | SDK Demo Application
      • Android | SDK Demo Application
      • Android | Java | SDK Demo Application
      • Flutter | SDK Demo Application
    • SDK Changelog
      • Android SDK Changelog
      • iOS SDK Changelog
    • Permissions Guides
      • First Launch
        • iOS 13 (and higher) Permissions Guide
        • iOS 12 (and lower) Permissions Guide
        • Android 9 Permissions Guide
        • Android 9 XIaomi Permissions Guide
        • Android 10 Permissions Guide
      • *Troubleshooting
        • iOS — Troubleshooting
          • iOS — Troubleshooting
        • Android — Troubleshooting
          • Samsung — Troubleshooting
          • Oppo — Troubleshooting
          • Huawei — Troubleshooting
          • Xiaomi — Troubleshotting
          • OnePlus — Troubleshooting
          • Meizu — Troubleshooting
          • Asus — Troubleshooting
          • Vivo — Troubleshooting
          • Wiko — Troubleshooting
  • Step 3: Register SDK users
    • User Registration (API)
  • Step 4: API | User Statistics, Scores, Trips
    • Step 4: Get Statistics, Scorings and Trip Data
    • API Authorization
    • Statistics and Scoring APIs
      • Get started - Statistics and Scoring API
      • User | Individual Scorings and Statistics
      • Admin | User(s) - Scorings and Statistics
      • Admin | Consolidated Scorings and Statistics
    • Trips API
      • Get a short list of tracks
      • Get a list of tracks with paging
      • Get a list of tracks by IDs
      • Get a single track with waypoints
      • Get the most earliest track
      • Track Statuses
  • SDK Features
    • *Bluetooth Device - Get started
      • *Get Started
      • *Android - ELM API
      • *iOS - ELM API
    • Trip Tags - Get started
      • Tags for trips via mobile app
        • Android - Tags for trips
        • iOS - Tags for trips
      • Tags for period
      • Trip log by tags
  • PLATFORM FEATURES
    • *User Management
      • *User Registration
      • *Check User Existence
      • *User Management
    • *Vehicle Management
      • *Directories
      • *Vehicles
    • FNOL, Inspections & Damage Recognition
      • Get started
      • Profiles
      • Claims
      • Vehicle inspections
        • Dictionary of vehicle photos
      • Photo processing
    • *Leaderboard
      • *Summary Leaderboard
      • *Leaderboard by factors
      • Swagger - Leaderboard
    • *Streaks
    • *SNS
      • *How to register AWS SNS
    • 3rd party data processing
      • Swagger - Incoming getaway
    • *User & Permissions Status | Heartbeats
  • Other
    • Response Codes
    • Resources swaggers
      • Swagger: User service
      • Swagger: Scorings and Statistics API
      • Swagger: Telematics data
      • Swagger: Leaderboard
      • Swagger: Vehicle Management
      • Driving details
      • Swagger: FNOL, Inspections & Damage Recognition
      • Swagger: Heartbeats
    • Archive
      • Get started
      • Statistics and Scorings API
      • Step 5: Get statistics and trip data [ARCHIVED]
      • User Statistics API [Archived]
      • SDK - Statistics API [ARCHIVED]
        • Get the data to the Android app
          • Android Telematics data (Tracks)
            • Check current running track state
            • Get start date for current recording trip
            • Register tracking state listener (for onStartTracking/onStopTracking events)
            • Register speed violations listener
            • Get flag for registered speed violations listener
            • Get registered speed limit in km/h or default
            • Get registered speed violations timeout in ms or default
            • Get Tracks
            • Get detailed trips information
            • Get available user roles
            • Change a user role (any of TrackOriginDictionary.code)
          • Android User Statistics
            • Get Dashboard info
            • Get detailed Dashboard
            • Get Driving time statistics
            • Get Speeding statistics
            • Get Mileage statistics
            • Get Distracted Phone Usage statistics
        • Get the data to the iOS app
          • Other methods
          • iOS Telematics data (tracks)
            • Request all Tracks with specified offset and limit
            • Request all Tracks with specified offset and limit. No filter will be used in request
            • Request Track info with specified Track Token
            • Request Track origins dictionary
            • Change Track Origin Code
            • Share Track
          • iOS User Statistics
            • Get shared Track
            • Request main statistics data for all possible statistic types
            • NS_ENUM
            • Request main statistics data for all possible statistic types
            • Properties and Protocols
      • Get all DeviceTokens
    • Report a bug
    • Data Hub
    • Talk to sales
  • Postman collection
Powered by GitBook
On this page
  • Getting Started
  • Bluetooth Low Energy (BLE)
  • Register a callback
  • Scan devices
  • Connect to ELM device
  • Get information about session

Was this helpful?

  1. SDK Features
  2. *Bluetooth Device - Get started

*Android - ELM API

Getting Started

First of all you should enable working with ELM feature on initialization step:

Your Application class
**
* Default Setting constructor
* Stop tracking time is 5 minute.
* Parking radius is 100 meters.
* Auto start tracking is true.
* hfOn - true if HIGH FREQUENCY data recording from sensors (acc, gyro) is ON and false otherwise.
* isElmOn - true <- to enable ELM  
*/
val settings = Settings(Settings.stopTrackingTimeHigh, Settings.accuracyHigh, true, true, true)

TrackingApi.getInstance().initialize(this, settings)

Bluetooth Low Energy (BLE)

Feature will not work if smartphone doesn't support Bluetooth Low Energy.

First of all check it by this way:

if (!packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
   // inform user about his device doesn't support BLE
 }

If smartphone supports BLE you should turn it ON:

// get Bluetooth adapter and check is it enabled or not
val mBluetoothAdapter = BluetoothUtils.getBluetoothAdapter(this)
mBluetoothAdapter?.let {
    if (!mBluetoothAdapter.isEnabled) {
        // ask user to enable Bluetooth if it's off
        val intent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
        startActivityForResult(intent, Constants.REQUEST_BLUETOOTH_ENABLE_CODE)
    } else {
        // Bluetooth is enabled already
    }
}

...

// handle result of Bluetooth enable
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    if (requestCode == Constants.REQUEST_BLUETOOTH_ENABLE_CODE && resultCode == Activity.RESULT_OK) {
            // Bluetooth successfully enabled
    } else {
        // user didn't enabled Bluetooth
    }
    super.onActivityResult(requestCode, resultCode, data)
}
    

Register a callback

If smartphone supports BLE and it's turned on you can scan ELM-devices and connect to it .

All interaction with ELM-devices are realised inside VehicleElmManager . You can get it by:

TrackingApi.getInstance().getElmManager()

To receive a callbacks from VehicleElmManager you should register a ElmLinkingListener .

It has 4 methods inside:

  • onScanningComplete - method will be called after successfull devices searching. It has a list of founded devices inside.

  • onScanningFailed - method will be called if error occures when scanning BLE-devices. Method has inside an error that you can handle like in example below.

  • onLinkingComplete - method will be called when smartphone was successfully paired with ELM-device. Returnes token of the vehicle and ELM-device Mac-address string.

  • onLinkingFailed - method will be called if some error occures during connection process.

    Method has inside an error that you can handle like in example below.


// initialize callback
val elmLinkingLister = object : ElmLinkingListener {
		override fun onScanningComplete(foundDevices: List<ElmDevice>) {
			// choose your device from foundedDevices list
		}

		override fun onScanningFailed(error: ElmLinkingError) {
			// error occurred during the scanning
			when (error) {
				ElmLinkingError.SERVER_ERROR_NETWORK_CONNECTION_NOT_AVAILABLE-> {
					// network error, check your connection and try again
				}
				ElmLinkingError.SERVER_ERROR_UNKNOWN -> {
					// error on server side, try again or contact the support
				}
				else -> {
					// unknown error, try again
				}
			}
		}

		override fun onLinkingFailed(error: ElmLinkingError) {
			// error occurred when device was pairing with smartphone
			when (error) {
				ElmLinkingError.SERVER_ERROR_NETWORK_CONNECTION_NOT_AVAILABLE-> {
					// network error, check your connection and try again
				}
				ElmLinkingError.SERVER_ERROR_UNKNOWN -> {
					// error on server side, try again or contact the support
				}
				ElmLinkingError.VEHICLE_NOT_SUPPORTED -> {
					// not supported vehicle
				}
				else -> {
					// unknown error, try again
				}
			}
		}

		override fun onLinkingComplete(vehicleToken: String, elmMAC: String) {
			// elm device was successfully paired with vehicle.
		}
	}

After that you should register it:

TrackingApi.getInstance().getElmManager()?.registerLinkingListener(elmLinkingLister)

Important! Dont forget to unregister a callback when it isn't needed to avoid memory leaks:

TrackingApi.getInstance().getElmManager()?.unregisterLinkingListener()

Scan devices

After successfully registering a callback to VehicleElmManager you can start a devices scanning:

TrackingApi.getInstance().getElmManager()?.getElmDevices()

getElmDevices method will scan Bluetooth devices and submit them to onScanningComplete method . After that you should choose your ELM-device from the list. If something went wrong error will be submitted to onScanningFailed method of the callback.

Connect to ELM device

First of all you should get list of the registered vehicles:

TrackingApi.getInstance().getElmManager()?.getVehicles()

You should call this method on a separate thread. Otherwise android.os.NetworkOnMainThreadExceptionwill be thrown

It will return an array of registered vehicles (Array<RegisteredVehicle>).

Choose you vehicle from the list and connect it to ELM-device (that you found on scanning step):

TrackingApi.getInstance().getElmManager()?.connectAndRegisterDevice(device.deviceMacAddress!!, selectedCar.token)

You should pass to connectAndRegisterDevice method two parameters:

  1. ELM-device mac-Address (String)

  2. Car token (String)

Method will pair Bluetooth device with your car and submit the result to onLinkingComplete method of the callback. If something went wrong error will be submitted to onLinkingFailed method of the callback.

Get information about session

You can get info about session:

TrackingApi.getInstance().getElmManager()?.getLastSession()?.let { info: Pair<Boolean, Long> ->
   // handle result
}

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

  • fisrt - Boolean flag about is ELM-connected

  • second - Long is a UNIX-timestamp when ELM device was connected

Happy coding!

Previous*Get StartedNext*iOS - ELM API

Last updated 4 years ago

Was this helpful?

For further work you should have registered vehicle(-s) on your account. More information about managing vehicles you can find .

here