Table of Contents
Installation
Add the truemetrics SDK to your app’sbuild.gradle
file:
Quick Start
1. Initialize the SDK in your Application class
2. Start and stop recordings
Configuration
The SDK is configured using theSdkConfiguration.Builder
class. Here are all available options:
Basic Configuration
Custom Foreground Notification
Customize the notification shown when the SDK is running as a foreground service:Core Features
Recording Management
Metadata Logging
Attach custom metadata to your recordings for better analysis:Lifecycle Integration
The SDK automatically handles Android application lifecycle events, but you can also integrate with your own lifecycle observers:Complete Cleanup
When you need to completely shut down the SDK:deinitialize()
, the SDK instance becomes unusable. You must call
init()
again to use the SDK.
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. Recording Management
- Check recording status before starting/stopping
- Use metadata to provide context for your recordings
- Consider auto-start delays for better user experience
3. Data Observation
- Use lifecycle-aware components when observing flows
- Only observe flows when you need the data
- Handle null values appropriately
4. Error Handling
5. Resource Management
- Only call
deinitialize()
when you’re completely done with the SDK - Use appropriate lifecycle scopes for flow collection
- Monitor storage usage in production apps
Debugging
Monitor SDK status for diagnostic information:API Reference
truemetricsSdk
Method | Return Type | Description |
---|---|---|
init(context, config) | truemetricsSdk | Initialize SDK (static) |
getInstance() | truemetricsSdk | Get singleton instance (static) |
startRecording() | Unit | Start sensor recording |
stopRecording() | Unit | Stop sensor recording |
isRecordingInProgress() | Boolean | Check if recording active |
isRecordingStopped() | Boolean | Check if recording stopped |
logMetadata(payload) | Unit | Log custom metadata |
setAllSensorsEnabled(enabled) | Unit | Enable/disable all sensors |
getAllSensorsEnabled() | Boolean | Get sensor enable status |
getRecordingStartTime() | Long | Get recording start timestamp |
getDatabaseSize() | String | Get current database size |
getActiveConfig() | SdkConfiguration? | Get active configuration |
deinitialize() | Unit | Shutdown SDK completely |
Observable Flows
Flow | Type | Description |
---|---|---|
deviceIdFlow | StateFlow<String?> | Unique device identifier |
sensorStats | StateFlow<List<SensorStats>> | Sensor statistics |
trafficInfo | StateFlow<TrafficInfo> | Network usage data |
recordingsCount | StateFlow<Long> | Number of recordings |
databaseSize | StateFlow<String> | Database size string |
sensorInfo | StateFlow<Iterable<SensorInfo>> | Available sensors info |
sdkStatus | StateFlow<Status> | SDK operational status |
Observer Methods
Method | Return Type | Description |
---|---|---|
observeSdkStatus() | Flow<Status> | Observe SDK status changes |
observerSensorStats() | Flow<List<SensorStats>> | Observe sensor statistics |
observerTrafficInfo() | Flow<TrafficInfo> | Observe network traffic |
observerRecordingCount() | Flow<Long> | Observe recording count |
observeDatabaseSize() | Flow<String> | Observe database size |
getStorageInfo() | Flow<String> | Observe storage information |
getActiveConfigFlow() | Flow<SdkConfiguration?>? | Observe config changes |