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
  • New events
  • Deprecated events

Setting up Broadcast receiver


  1. Add available 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
    }
}
  1. Add this broadcast receiver to the manifest before the </application> tag.
<receiver android:name=".TrackingReceiver"/>
  1. 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()

Did this page help you?