# \*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:

```kotlin
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.

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

Register it:

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

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

```kotlin
TrackingApi.getInstance().unregisterTrackingEventsReceiver()
```

## Listeners

### Start and stop tracking callback

```kotlin
// 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

{% hint style="info" %}
This feature is available from **2.2.228** version. Latest release you can check on [**Changelog page**](/sdk-installation/changelog/android-changelog.md)
{% endhint %}

```kotlin
// 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

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-old.telematicssdk.com/sdk-installation/android-sdk-installation/subscribe-to-tracking-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
