SDKs & Sample Apps
SDKs

MTS SDK

30min

Introduction

MTS The Movement Tracking System (MTS) SDK is an Android SDK written in Java and Kotlin that enables real-time tracking of users and vehicles. It supports integration with both native Android and React Native applications, providing a reliable solution for monitoring movement and managing geofencing events.

The SDK includes a set of APIs that facilitate seamless communication with OS1 backend services, allowing developers to efficiently track movement, listen for event updates, and manage location-based triggers.

Features

  • Real-time Tracking – Capture and transmit live location updates.
  • Event Listener Support – Subscribe to movement events and trip status updates.
  • Geofencing – Define virtual boundaries and receive entry/exit notifications.
  • Flexible Integration – Supports both native Android and React Native applications.
  • Sync Location Trace both through REST API & MQTT (MQ Telemetry Transport) Protocol.

The MTS SDK is designed for applications that require accurate movement tracking, geofencing capabilities, and event-driven monitoring.

Currently, supports 21=<SDK<=29.

Prerequisites

  • Android application written in Java or Kotlin
  • Minimum Android API level 21 (Lollipop)
  • Internet access for API communication
  • OS1 backend services configured and accessible

Supported Versions

  • Minimum SDK: 24
  • Maximum SDK: 34

Step 1: Installation

To install MTS SDK, run the following command:

Text


Step 2: Import MTS SDK

  1. Import MTS SDK in your project:
JS


2. Register the token expiry sync task in the root index file (index.ts):

JS


Step 3: Modify MTS Default Configuration

The MTS SDK provides default configuration values that can be modified based on your specific use case. While modifying these values is optional, it allows you to fine-tune parameters such as location update frequency, accuracy, and data transmission behavior to better align with your application's needs.

Below is the default configuration provided by the SDK:

JS


Configuration Parameters

Parameter

Type

Default Value

Description

locationFrequency

number

10000

Time interval (in ms) for location updates.

distanceAccuracyLimit

number

250

Accuracy threshold in meters.

speedLimit

number

28

Maximum speed threshold in meters per second.

mode

enum

HYBRID

MTS operation mode (HYBRID, GPS_ONLY, etc.).

environment

enum

DEV

SDK environment (DEV or PROD).

batchSize

number

25

Number of location events sent per batch.

isMqttCleanSession

boolean

true

Determines whether MQTT uses a clean session.

mqttKeepAliveInterval

number

900 (15 min)

MQTT keep-alive interval in seconds.

maxLocationAge

number

15000

Maximum allowed location age in milliseconds.

maxTraceSession

number

8640000

Maximum session duration in milliseconds.

isOdometerEnabled

boolean

true

Enables odometer tracking.

retriesBeforeFallback

number

1

Number of retry attempts before fallback.

httpFailureLimit

number

5

Number of failed HTTP requests before stopping.

dataSendDelay

number

30000

Delay before sending data (milliseconds).

alarmTime

number

60000

Alarm trigger time in milliseconds.

missingSeqCheckDuration

number

300000 (5 min)

Interval for checking missing sequences (milliseconds).

odometerPushFrequency

number

300000 (5 min)

Frequency of odometer updates (milliseconds).

qosLevel

number

1

MQTT Quality of Service level (0 or 1).

When to Modify These Defaults?

  • If your application requires more frequent location updates, reduce locationFrequency.
  • To improve accuracy, adjust distanceAccuracyLimit.
  • If battery optimization is a concern, increase dataSendDelay to reduce network usage.

Step 4: Check For Mandatory MTS Permissions

Ensure that mandatory permissions are granted before using MTS SDK:

JS


Step 5: Initializing MTS

JS


See Error Codes for Possible error types.

1. Start Event

JS


2. Publish Event

JS


3. Stop Event

JS


4. Flush MTS traces data

JS


Error Codes

PERMISSIONS_ERROR[2500] = "Mandatory Android Permissions not provided" MTS_INIT_ERROR[2501] ="MTS INIT Not called! MTS Device ID is Empty" PARAM_MISSING[2502] = "Mandatory Paramater is missing in request"

MTS Geofencing Introduction

MTS SDK provides a real-time geofencing feature that:

  1. Tracks user ENTRY/EXIT events
  2. Syncs geofence events to the server in real-time
  3. Works in the background even if the app is killed

Starting Geofencing Process

Geofencing process can only be started post calling "startMTS()" in your code. Whenever a geofence event is captured by MTS SDK. It will perform two actions:

  1. It will emit an event referring to a Geofence ENTRY/ EXIT to the integrating application.
  2. It will add an EVENT object to the existing MTS traces object.

Note: Ensure MTS service is running before calling startGeofence().

Step 1: Start Geofencing Process

Ensure MTS service is running before calling startGeofence().

JS


Step 2: Call startGeofence() function:

JS


Important Note About startGeofence() function call:

  1. Ensure that the MTS service is running before calling startGeofence(). Always invoke startMTS() first to start the MTS process before initiating geofencing.
  2. If startGeofence() is called again with the same geofenceRef value and abortExisting set to true, the existing geofence process will be terminated, and a new geofence process will be initiated with the same geofenceRef.

Step 3: Abort Geofencing Process

JS


Step 4: Check Geofencing Process Status

JS


Possible return values:

  1. "ON-GOING"
  2. "ABORTED"
  3. "NO_STATUS_FOUND"

Geofence Event Updates

When a user enters/exits a geofence, the SDK:

  1. Emits an event to the integrating application:
    • GEOFENCE_ENTRY: User enters geofence
    • GEOFENCE_EXIT: User exits geofence
  2. Adds an event object to the MTS traces object

Example Event Object

JS


Listening Geofence Events

How to listen a geofence event on application end whenever an ENTRY/ EXIT event occurs: Events Constants: 1. GEOFENCE_ENTRY 2. GEOFENCE_EXIT

JS


Flush Geofence DB

JS


Geofence Error Codes

  • START_GEOFENCE_ERROR_CODE[2507] = "Geofence start failed. Please try again".
  • CHECK_GEOFENCE_STATUS_ERROR_CODE[2508] = "Geofence status check failed. Please try again".
  • ABORT_GEOFENCE_ERROR_CODE[2509] = "Geofence abort failed. Please try again".
  • FLUSH_GEOFENCE_ERROR_CODE[2510] = "Geofence data flush failed. Please try again".



Updated 11 Mar 2025
Did this page help you?