*Android - ELM API
Getting Started
First of all you should enable working with ELM feature on initialization step:
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 smartphone supports BLE you should turn it ON:
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:
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.
After that you should register it:
Important! Dont forget to unregister a callback when it isn't needed to avoid memory leaks:
Scan devices
After successfully registering a callback to VehicleElmManager
you can start a devices scanning:
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
For further work you should have registered vehicle(-s) on your account. More information about managing vehicles you can find here.
First of all you should get list of the registered vehicles:
You should call this method on a separate thread.
Otherwise android.os.NetworkOnMainThreadException
will 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):
You should pass to connectAndRegisterDevice
method two parameters:
ELM-device mac-Address (
String
)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:
It has inside a Pair<Boolean, Long>
where:
fisrt -
Boolean
flag about is ELM-connectedsecond -
Long
is a UNIX-timestamp when ELM device was connected
Happy coding!
Last updated