*Setup and enable SDK

Overview

SDK setup is separated to 3 parts:

  1. Initialization

  2. Grating all required permissions

  3. Enabling sdk

Initialize SDK

Create Settings object

For SDK version 2.2.217 and newer:

/**
* 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 if data recording from ELM327 devices is ON and false otherwise.
*/
val settings = Settings(Settings.stopTrackingTimeHigh, Settings.accuracyHigh, true, true, true)

For SDK version < 2.2.217:

/**
* Default Setting constructor
* IsSensorFull - true
* Stop tracking time is 5 minute.
* Parking radius is 100 meters.
* Auto start tracking is true.
*/
val settings = Settings(true, Settings.stopTrackingTimeHigh, Settings.accuracyHigh, true)

initialize SDK.

// call this in your Application class
val api = TrackingApi.getInstance()
api.initialize(this, settings)

Grant RUNTIME permissions.

In your application you need to request runtime permissions (see list below) for the SDK to work correctly. So request them prior to enable SDK and start tracking.

android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.ACCESS_BACKGROUND_LOCATION (for Android >=10 (Q))
android.Manifest.permission.ACTIVITY_RECOGNITION (for Android >=10 (Q))
android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

Or you can just use our Permission wizard or Permissions dialog. Both of them contais all needed logic for asking required permissions and they are fully compatible with new Google politics.

Enable/disable SDK.

Befor enabling the SDK you should check are all required permissions granted. And only after that you can enable the SDK.

Following code sample shows how to do it:

val trackingApi = TrackingApi.getInstance()
if (trackingApi.isAllRequiredPermissionsAndSensorsGranted()) {
   trackingApi.setDeviceID("YOUR DEVICE ID") // DEV_ID from Raxel
   trackingApi.setEnableSdk(true) 
} 

If you want to disable sdk:

trackingApi.setEnableSdk(false)

The following code sample shows how to logout from sdk:

trackingApi.setEnableSdk(false)
trackingApi.clearDeviceID()

Firstly, you should disable sdk and after that clear the device id.

Disable SDK after tracks uploading

There is a case when user wants to disable the sdk after trip was ended. Common case looks like this:

  1. Subscibe to tracking events and listen to onStopTracking method

  2. Disable sdk by TrackingApi.getInstance().setEnableSdk(false)

But there is on important moment: sdk can be disabled and recorded track may not be uploaded. Because track uploading may take some time. For that purpose you can use TrackingApi.getInstance().setDisableWithUpload() method. It will wait until all tracks will be uploaded and only after that SDK will be disabled.

When SDK is waiting to tracks uploading notification text will be changed to Waiting for the tracks uploading

Also you can override this resource on your side: <string name="tracking_notification_looking_for_tracks_upload" >Waiting for the tracks uploading</string>

Last updated