Skip to main content
The Truemetrics SDK provides advanced sensor data collection and analytics capabilities for Android applications. This guide covers all aspects of integrating and using the SDK effectively.

Table of Contents


Installation

Add the following to your root-level build.gradle file (or settings.gradle):
Then add the dependency to your app-level build.gradle:
Google Play foreground-service declaration (SDK 1.5.7+): the SDK’s recording service declares the location and dataSync foreground-service types (previously location + specialUse). In the Play Console foreground-service-types form, declare “Location” and “Data sync” for the Truemetrics recording service (and the optional sensor-watchdog service, if enabled). If your existing declaration listed “Special use” for a Truemetrics service, replace it with “Data sync” (keep “Location”).

Quick Start

1. Initialize the SDK in your Application class

2. Start and stop recordings


Initialization Lifecycle

TruemetricsSdk.init() returns immediately but the SDK is not ready for use until it reaches Status.Initialized. Initialization runs asynchronously in the background: it binds a foreground service, then fetches the configuration from the backend.

State Transitions

How Long To Wait

There is no hard timeout on initialization. Under poor connectivity the SDK stays in Status.Initializing and keeps retrying. Do not impose an arbitrary client-side timeout — either wait for Status.Initialized/Status.Error, or gate UI on getDeviceId() becoming non-null.

Checking Initialization Status

Recommended — observe the status flow and wait for Status.Initialized:
Non-blocking — react to state changes as they arrive:
Quick synchronous checkgetDeviceId() returns null until initialization completes:

Calling Other APIs Before Initialization Completes

  • startRecording() — safe to call immediately after init(). If the service is not yet bound, the request is queued and executed once binding completes. However, if called after the service binds but before the config fetch succeeds, it will transition the SDK to Status.Error(CONFIG_ERROR). To avoid this, either await Status.Initialized first, or rely on the auto-start configuration (see Configuration).
  • logMetadata() — ignored with a log warning if called before initialization. Wait for Status.Initialized before logging.
  • getDeviceId(), getActiveConfig(), getUploadStatistics(), getSensorStatistics() — return null until initialization completes.

Terminal vs. Transient Failures


Configuration

The SDK is configured using the SdkConfiguration.Builder class.

Basic Configuration

Custom Foreground Notification

Customize the notification shown when the SDK is running as a foreground service using the SDK’s notification channel:

Core Features

Recording Management

Device ID

Get the unique device identifier (available after initialization):
The device ID may rotate automatically based on a server-configured TTL. When expired, a new ID is generated transparently on the next initialization.

Metadata Logging

Log standardized delivery/pickup event metadata:
The map-based logMetadata(Map<String, String>) overload is deprecated. Use logMetadata(StandardMetadata) instead. For advanced metadata with templates and tags, see Metadata Guide.

Sensor Management

Complete Cleanup

Warning: After calling deinitialize(), the SDK instance becomes unusable. You must call init() again to use the SDK.

SDK Status

Monitor the SDK state using observeSdkStatus():

Error Codes


Statistics API

Upload Statistics

Monitor upload health:

Sensor Statistics

Get detailed sensor data quality:
Quality levels:
  • EXCELLENT: 95-100% of configured frequency
  • GOOD: 80-95%
  • POOR: 50-80%
  • BAD: less than 50%
  • UNKNOWN: no data or not recording

Best Practices

1. Initialization

  • Always initialize in your Application class
  • Use the application context, not activity context
  • Initialize once and reuse the singleton instance

2. Error Handling

3. Monitoring SDK Health


API Reference

TruemetricsSdk

Observable Flows

Data Classes

UploadStatistics

SensorStatistics

SensorInfo