Setup and maven repository
Project requires Java 17. If necessary, adjust your Java version in your IDE, typically inIDE's File -> Project structure -> SDK Location.
As next step update your project-level settings.gradle file and dependencyResolutionManagement section by the following:
Declare dependency on TruemetricsSDK
Inside yourbuild.gradle add the following dependency:
Initialize SDK
SDK behaves like a singleton object that manages its own internal state. Before actually using the SDK you need to initialize it:Config object also accepts Boolean debug parameter. Set it to true if you want to see LogCat output of the SDK. Make sure the parameter is false for release builds.
Foreground service and notification
In order to reliably collect data, SDK starts a Foreground service and shows a notification while recording is in progress. By default, SDK uses it’s own notification for this purpose. If you want to use your own, you can pass it inConfig object as foregroundNotification parameter.
Make sure to ask user for notification permission if device runs Android 13 or later.
Below you can find sample code for creating notification channel and Notification itself.
Creating a notification channel using NotificationManagerCompat:
Status callback
Set SDK status callback to get notified about SDK state changes and potential errors:onError callback will be invoked when something happens that prevents SDK from operating, e.g. API KEY authorization fails, device storage gets full, etc.
Possible error codes:
| Error code | Description |
|---|---|
| AUTHENTICATION_ERROR | API key is not valid, expired or revoked |
| UPLOAD_ERROR | Recordings couldn’t be uploaded after exhausting all attempts |
| STORAGE_FULL | Device storage is full which prevents saving sensor readings |
| MISSING_NOTIFICATION_PERMISSION | Permission to post notification is not granted which means that Foreground service cannot be started |
| SENSORS_NOT_WORKING | Some sensors are not wokring as intented. Error message should indicate if any required permissions are missing |
askPermissions callback will be invoked based on necesarry permissions for enabled sensors in remote configuration. At the moment, list of permission can include:
android.permission.READ_PHONE_STATEandroid.permission.ACTIVITY_RECOGNITIONandroid.permission.ACCESS_COARSE_LOCATIONandroid.permission.ACCESS_FINE_LOCATIONandroid.permission.ACCESS_BACKGROUND_LOCATION
Start recording
Config in system’s status bar. Recording will continue even when app exits.