Initializing the SDK
The SDK needs to be initialized with some basic settings (such as the directory the SDK can use for data storage and logs), and with a TokenSigner
that is provided by the host application. This must occur early in the lifecycle of the app.
Create a class to implement the TokenSigner
(see example below):
Next, create a class to configure/initialize the SDK (see example below):
NOTE: Classes can (and should) be renamed, as appropriate.
WARNING: Failing to initialize the SDK before using its functionality will result in unexpected behaviour.
Beginning Trip Detection Manager
To upload trip data, the current mobile device must be activated for data collection through the Portal
. This is to ensure trip data can be analyzed properly on the IMS backend. Depending on the mode of activation the host application chooses and the design of the app, device activation may only need to be performed once for a device.
Identity
The host application shares the identity of its currently authenticated user by sharing an Identity
object with the SDK. An Identity
is constructed with the host application's API Key and the host application's unique user identifier, provided during the enrolment process.
UploadRoute
The host application can choose upload route for uploading trip files which can be passed during the initialization of the SDK.
For more details about upload routes check Controlling how the files are uploaded
Feature
The features
: [Feature]
parameter of TripDetectionManager's initializer specifies which features are used for Trip Detection and Trip Validation. A combination of Trip Detectors and Trip Validators can be passed into the initializer to meet the needs of the App. Simply declare all Feature
components that are needed.
A standard setup would include at least one Trip Detector and one Trip Validator. For example, a phone only trip detection configuration would include [Feature.Geofence]
and [Feature.PhoneOnlyValidation]
.
Trip Detection
Feature.Geofence: To use geofences for trip detection, pass in [Feature.Geofence].
This feature provides trip detection using Core Motion and Core Location functionalities.
Feature.Bluetooth: To use Bluetooth devices for trip detection, pass in [Feature.Bluetooth].
This feature uses Core Bluetooth functionality to have trip detection using a bluetooth device (i.e. wedge).
NOTE: If there is no Trip Detection Feature parameter passed in the configuration, Trip Detection functionality will be limited.
Trip Validation
Starting with the SDK 1.15.0, the host app can provide the trip validation features as in the example above during the initialization of SDK.
Feature.PhoneOnlyValidation: To use phone-only trip validation feature, pass in [Feature.PhoneOnlyValidation].
This feature allows a trip to be validated using the onboard sensors of the phone.
Feature.DeviceValidation: To use Bluetooth devices for trip validation feature, pass [Feature.DeviceValidation].
This feature allows a trip to be validated by the presence of an associated Bluetooth device during the trip.
NOTE: If there is no Trip Validation Feature parameter passed in the configuration, trips will be validated as soon as they are detected.
Complete Example
We can create a class that contains all of the trip detection methods listed above:
Configure Bluetooth Device Provider
Starting with SDK 1.19.0, host app has the capabilities to configure the device providers
Host app can use the new
Devices
andIMSBluetooth
frameworks to configure the bluetooth usage for TripDetection. Both frameworks are required to be included in the project if the trip detection variant is using bluetooth and devices to detect trips.
Concrete Example
The Devices module provides APIs as listed below:
scanForDevices: To scan bluetooth devices
associateDevice: To associate an IMS device
disassociateDevice: To disassociate an IMS device
clearAllAssociatedDevices: To clear all associated devices
associatedDevices: To retrieve already associated devices
Below is the snapshot for understanding the configuration required to utilize the new modules:
SDK initialization feedback
Starting with the SDK 1.10, it is possible to add a handler to be notified of SDK status changes. Setting a handler:
Removing the current handler:
These can be added to the Trip Detection Manager class.
NOTE: The list of statuses will be expanded in future releases.
Last updated