*Subscribe to tracking events

Tracking events broadcast receiver

You can implement an instance of TrackingEventsReceiver and subscribe to tracking events.

Add following class to your application:

class TrackingReceiver : TrackingEventsReceiver() {
	override fun onLocationChanged(context: Context, location: Location) {
		// Location updates
	}
	override fun onStartTracking(context: Context) {
        // tracking was started
	}
	override fun onStopTracking(context: Context) {
		// tracking was stopped
	}
	override fun onSpeedViolation(context: Context, violation: SpeedViolation) {
		// Receive speed violation
	}

	override fun onNewEvents(context: Context, events: Array<Event>) {
		// receive an updates about new events
	}

	override fun onSdkDeprecated(context: Context) {
		// receive callback about deprecated events
	}
}

Add this broadcast receiver to the manifest before the </application> tag.

<receiver android:name=".TrackingReceiver"/>

Register it:

TrackingApi.getInstance().registerTrackingEventsReceiver(TrackingReceiver::class.java)

Don't forget to unregister when it’s not needed:

TrackingApi.getInstance().unregisterTrackingEventsReceiver()

Listeners

Start and stop tracking callback

// initialize callback
val callback = object : TrackingStateListener {
		override fun onStopTracking() {
			// tracking stopped
		}		override fun onStartTracking() {
			// tracking started
		}
	}
// register it in SDK
TrackingApi.getInstance().registerCallback(callback)

Callback to be invoked when new location was found

This feature is available from 2.2.228 version. Latest release you can check on Changelog page

// 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 callback

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()

Last updated