Table of Contents
- Installation
- Quick Start
- Initialization Lifecycle
- Configuration
- Core Features
- SDK Status
- Statistics API
- Best Practices
- API Reference
Installation
Add the following to your root-levelbuild.gradle file (or settings.gradle):
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 forStatus.Initialized:
getDeviceId() returns null until initialization completes:
Calling Other APIs Before Initialization Completes
startRecording()— safe to call immediately afterinit(). If the service is not yet bound, the request is queued and executed once binding completes. If initialization has failed, the call transitions the SDK toStatus.Error(CONFIG_ERROR); if the SDK was never initialized, toStatus.Error(NOT_INITIALIZED). To avoid the first, awaitStatus.Initializedbefore calling it, or configure an auto-start (see Recording lifecycle).logMetadata()— ignored with a log warning if called before initialization. Wait forStatus.Initializedbefore logging.getDeviceId(),getActiveConfig(),getUploadStatistics(),getSensorStatistics()— returnnulluntil initialization completes.
Terminal vs. Transient Failures
Configuration
The SDK is configured using theSdkConfiguration.Builder class.
Basic Configuration
Recording lifecycle
init() does not start recording. A recording begins when the host calls startRecording(), and
continues until stopRecording() or deinitialize().
A recording that was started is resumed automatically the next time the app initializes the SDK,
so an app that is killed, restarted or updated mid-recording picks up where it left off. init() is
what performs that resume — it never stops an active recording.
To have the SDK start recording on its own instead, configure a delay:
Status.DelayedStart. Calling
stopRecording() in that window cancels the pending start. The default is
SdkConfiguration.EXPLICIT_START, and any negative value means the same thing: wait for an explicit
startRecording().
Changed in 1.6.0. Releases 1.3.0 through 1.5.x defaulted to
AUTO_START_ON_INIT, so an app that
called init() was recording even if it never called startRecording(). If you relied on that,
set delayAutoStartRecording(SdkConfiguration.AUTO_START_ON_INIT) explicitly. A device that was
recording when it was updated keeps recording until it is stopped once with stopRecording() or
deinitialize(); every launch after that follows the new default.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: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
deinitialize(), the SDK instance becomes unusable. You must call
init() again to use the SDK.
SDK Status
Monitor the SDK state usingobserveSdkStatus():
Error Codes
Statistics API
Upload Statistics
Monitor upload health:Sensor Statistics
Get detailed sensor data quality:- 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
Applicationclass - Use the application context, not activity context
- Initialize once and reuse the singleton instance