Android Setup

< Back

Welcome to the official documentation for How to implement the Locator SDK for Android.

The SDK follows the definition described in LocatorService.

Android Release Notes described in Release Notes Androidarrow-up-right

Project configuration (Gradle)

Before using the SDK, you must configure the Android project with the required plugins and dependencies.

Versions and plugins (libs.versions.toml)

In your version catalog (libs.versions.toml), add (or adjust) the following entries:

[plugins]
android-library = { id = "com.android.library", version.ref = "agp" }
jetbrains-kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "kspVersion" }
google-services = { id = "com.google.gms.google-services", version.ref = "googleSvc" }

[versions]
agp = "8.13.1"
kotlin = "2.2.21"
kspVersion = "2.3.1"
googleSvc = "4.4.4"

Plugins in the project build.gradle

In the root build.gradle.kts file, register the plugins:

Plugins in project settings.gradle

In the settings.gradle.kts file (root project), add Azure's configurations:

SDK dependencies (app module)

In the build.gradle.kts of the application module (for example, app), add the SDK dependencies using the catalog:

Also make sure the library versions and mappings are defined in libs.versions.toml:

Plugins and configuration in the app build.gradle

In the application module build.gradle.kts, apply the required plugins:

And configure the android block with the options required by the SDK:

Initialization and Configuration

To use the SDK, you need to initialize it, get an instance, and configure it. The complete process can be done through a unified function that receives a LocatorConfig and executes all steps sequentially.

Step 1: Initialization in Application

First, initialize the SDK in your application's Application class:

Step 2: Complete Configuration

After initialization, you can configure the SDK in a unified way. The function below receives a LocatorConfig and optionally a LocatorIntegration, executing all necessary steps:

Usage Example

Step 3: Init Observed Mode

For the SDK Locator to enter observable mode, it collects and sends data in real time using the collectObservedModeIntervalMillis parameter of the LocatorConfig object as a collection interval reference.

LocatorConfig Structure

Integrator (LocatorIntegration)

The Integrator uses the LocatorIntegration interface:

By default, the SDK uses DefaultLocatorSDKIntegrationApiImpl. If you need a custom implementation, just implement the interface and pass it as a parameter to the setupLocatorSDK function.

Exceptions

Starting Location Collection

After configuration, you can start location collection by calling the SDK's start() method. This can be done automatically through the autoStart = true parameter in the setupLocatorSDK function, or manually:

Commands

To validate if a command should be executed by the Locator SDK, use the isLocatorSDKCommand method. If it belongs to the SDK, use convertLocatorSDKCommand to convert the message and execute for the SDK to run the command. Both methods belong to the LocatorSDK class as companion object methods, so there is no need for an instance to call these methods.

SDK Device Replacement Process

After confirming the replacement in the app, call the SDK's destroy method to clean up the data, stop data collection processes, geofences, drop detection, and data transmission via MQTT.

Notify the new device to initialize the SDK, pass the initial configuration, execute the start, and call syncAll to retrieve all SDK operating configurations on the new device. For this process, see the code snippet described in Step 2: Complete Configuration, adding only the sync all method call after the initial configuration.

Handling SDK start permissions

Added special handling for permissions when initializing location collection via the SDK's start() method.

This behavior consists of validating only the permissions necessary for data collection, permissions related to geolocation services and foreground services, excluding permissions related to other functionalities, such as audio capture, from the start() function.

It's important to note that the pendingPermissions method still returns all the permissions necessary for the SDK to function fully; however, permissions related to audio data will not interfere with location data collection.

The impact of not accepting these permissions is:

  • When entering SOS mode, if the permission(s) are not granted, the SDK will send the SOS mode entry and also send an event indicating that audio capture was not possible due to the permission(s).

Audio recording functionality after device initialization in SOS mode (optional)

Due to restrictions in the Android operating system, it is not possible to start recording audio after the device has been initialized.

When the device is turned off and the SDK Mode is set to SOS, the SDK's behavior is to start the real-time data collection service, send an event to MQTT indicating that the device has entered SOS mode, and begin recording. However, due to limitations, it will not be possible to start audio recording, the user will need to open the app once to access the device's microphone.

With this behavior, when the SDK Locator receives the system's signal to complete initialization, it will begin collecting real-time locations, sending the event to MQTT, and posting a notification with an app opening action using deeplink data configurable in the audioRecord parameter of the LocatorConfig object.

The audio recording stream is optional; you can either omit the bootNotification parameter within audioRecord of the LocatorConfig object or simply set it to null.

We will use deeplink and deeplink Value parameters in that way:

Periodic updates of Geofences

Starting with version 2.1.0, the SDK will have a control for periodic geofence updates, the update time is defined within the LocatorProcessConfig object named syncGeofencesIntervalMillis. If no value is passed, the application will use a default value of 3 hours.

The LocatorProcessConfig field is described within LocatorConfig as process.

In case of synchronization failure, the SDK will retry within a limited time of 30 minutes, after success, it will revert to using the value described in syncGeofencesIntervalMillis.

Points of Interest

Version 2.1.0

  • The POST_NOTIFICATIONS permission has been added to the SDK package. This is due to the use of sending notifications in the audio recording stream after the device boots in SOS mode, and this permission is required for the process to run. See permissions here.

< Back

Last updated