For Android apps
Introduction
You can implement an instance of TrackingEventsReceiver and subscribe to the following tracking events:
- Location update
- Tracking started
- Tracking stopped
- Speed violation
- Crash detected
- New events
- Deprecated events
Setting up Broadcast receiver
- Add available class to your application
class TrackingReceiver : TrackingEventsReceiver() {
override fun onLocationChanged(context: Context, location: Location) {
// new location found
}
override fun onStartTracking(context: Context) {
// tracking started
}
override fun onStopTracking(context: Context) {
// tracking stopped
}
override fun onSpeedViolation(context: Context, violation: SpeedViolation) {
// new speed violation
}
override fun onNewEvents(context: Context, events: Array<Event>) {
// filter accidents from events
events.filter { it.type == "Accident" }
}
override fun onSdkDeprecated(context: Context) {
// deprecated sdk callback
}
}
- Add this broadcast receiver to the manifest before the
</application>
tag.
<receiver android:name=".TrackingReceiver"/>
- Register that
TrackingApi.getInstance().registerTrackingEventsReceiver(TrackingReceiver::class.java)
Deactivate the registration when you don't need it.
TrackingApi.getInstance().unregisterTrackingEventsReceiver()
Callbacks
Start and Stop tracking
// initialize callback
val callback = object : TrackingStateListener {
override fun onStopTracking() {
// tracking stopped
} override fun onStartTracking() {
// tracking started
}
}
// register it in SDK
TrackingApi.getInstance().registerCallback(callback)
New location
// initialize callback
val callback = object : com.raxeltelematics.v2.sdk.LocationListener {
override fun onLocationChanged(location: Location?) {
// your logic here
}
}
// register it in SDK
TrackingApi.getInstance().setLocationListener(callback)
// Don't forget to remove callback by passing null to this method when it is not needed
TrackingApi.getInstance().setLocationListener(null)
Speed violation
val callback = object : com.raxeltelematics.v2.sdk.SpeedViolationsListener {
override fun onSpeedViolation(violation: SpeedViolation) {
// your logic here
}
}
// register it in SDK
TrackingApi.getInstance().registerSpeedViolations(speedLimit, speedTimeout, callback)
// Don't forget to remove callback by passing null to this method when it is not needed
TrackingApi.getInstance().unregisterSpeedViolationCallback()
Crash detected
override fun onNewEvents(context: Context, events: Array<Event>) {
// filter accidents from events
events.filter { it.type == "Accident" }
}
Updated almost 3 years ago