Skip to main content

Get started

Experimental API
The Driver Notifications API is in a preview state and has a high chance of being changed in the future.

This guide covers the most important steps to get started using the Driver Notifications API, with code snippets to help you start your implementation.

1. Configure credentials and set up repositories

For detailed instructions on configuring credentials, refer to the Get started page, and for guidance on initializing the SDK entry point, see the SDK Initialization guide.

2. Add the dependency

Add the library dependency to your build.gradle. The library version matches Navigation SDK version, they have the same release cadence. This way, you should not worry about version compatibility.

dependencies {
implementation "com.mapbox.navigationcore:driver-notification:3.17.0"
}

3. Instantiate and start DriverNotificationManager

val driverNotificationManagerOptions = DriverNotificationManagerOptions.Builder().build()
val driverNotificationManager = DriverNotificationManager(driverNotificationManagerOptions)
driverNotificationManager.start()

DriverNotificationManagerOptions is optional and can be omitted.

4. Add notification provider

Add one of the exposed providers that implements DriverNotificationProvider, such as SlowTrafficNotificationProvider.

val slowTrafficNotificationProvider = SlowTrafficNotificationProvider()
driverNotificationManager.attachDriverNotificationProvider(slowTrafficNotificationProvider)

5. Observe notifications with DriverNotificationManager instance

Use the before created instance of DriverNotificationManager to observe DriverNotification. All attached notification providers generate notifications that inherit from DriverNotification. Check the type to retrieve the details of the notification.

driverNotificationManager.observeDriverNotifications().collect { notification ->
when(notification) {
is SlowTrafficNotification -> handleSlowTrafficNotification(notification)
else -> handleOtherNotifications(notification)
}
}

6. Detach notifications provider from DriverNotificationManager instance

If you no longer need to receive a specific notification type, detach the before created DriverNotificationProvider instance from DriverNotificationManager.

driverNotificationManager.detachDriverNotificationProvider(slowTrafficNotificationProvider)

7. Stop DriverNotificationManager instance

Stop DriverNotificationManager instance when notifications are no longer required. For example, stop it if a user disables this feature in the application settings.

driverNotificationManager.stop()
Was this page helpful?