SDK Interface
Overview of the functionality of the SDK.
Setup and maven repository
Project requires Java 17. If necessary, adjust your Java version in your IDE, typically in IDE'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 your build.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 in Config
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
:
Creating a notification:
You can find example snippets for creating a notification channel and accompanying notification in the Demo app.
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_STATE
android.permission.ACTIVITY_RECOGNITION
android.permission.ACCESS_COARSE_LOCATION
android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_BACKGROUND_LOCATION
Please note:
We recommend that you implement status callback and handle at least SENSORS_NOT_WORKING error by stopping recording and notifying user that device may be faulty if app is given all necessary permissions but error still persists.
Start recording
Starting the recording also starts Foreground service and shows notification supplied in Config
in system’s status bar. Recording will continue even when app exits.
Stop recording
Stopping recording also stops Foreground service and removes notification.
Log metadata
SDK will serialize payload into JSON.
Most of our customers query the data by customer adresses. That means, that most costumers call the entrance endpoint by using the customer’s address as an identifier. Other customers seek more flexibility and also want to query data by an identifier for a route or a courier.
By sending this information from your app to our SDK, we enable you to filter the results by these identifiers later on. If you’re unsure about best practices for your use case, reach out, and we’ll guide you to the best solution or take a deeper look into the metadata chapter
Deinitialize SDK
De-initialization stops recording if in progress and tears down the SDK and cancels all scheduled uploads.