Get started
Refer to the Mapbox Navigation Framework install guide. This guide assumes your initial set up has been completed.
How to Enable Feedback Agent
To enable Feedback Agent in Navigation SDK, follow these steps:
Step 1: Add the dependency
Add the following dependency to your app-level build.gradle file:
implementation("com.mapbox.navigation:voicefeedback:2.22.1")
Step 2: Integrate feedback agent
// Create the ViewModel with feedback handling
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
internal class VoiceFeedbackViewModel : ViewModel() {
private val feedbackAgent = FeedbackAgentSession.Builder().build()
private val _viewState = MutableStateFlow(VoiceFeedbackViewState())
val viewState: StateFlow<VoiceFeedbackViewState> = _viewState.asStateFlow()
init {
// Handle ASR state changes and process feedback results
feedbackAgent.asrState.onEach { asrState ->
_viewState.value = when (asrState) {
is ASRState.Result -> {
val feedbackType = asrState.feedbackType
val feedbackDescription = asrState.text
postVoiceFeedback(feedbackType, feedbackDescription)
_viewState.value.copy(
state = "Result: $feedbackDescription",
connectionAvailable = false,
disconnectionAvailable = true,
startListeningAvailable = true,
stopListeningAvailable = false,
showSuccessMessage = true,
successMessage = "Voice feedback sent successfully: $feedbackType",
errorState = null,
)
}
// Handle other ASR states here.
}
}.launchIn(viewModelScope)
}
fun onConnectClicked() = feedbackAgent.connect()
fun onStartListeningClicked() = feedbackAgent.startListening()
fun onStopListeningClicked() = feedbackAgent.stopListening()
}
Step 3: Get the Feedback ID for an item
The Feedback SDK automatically generates a feedback ID for every feedback item. You can optionally track this value to close the feedback loop with your users and notify them when one of their items has been closed, for example. For more information, see Closing the Feedback Loop.
private suspend fun postVoiceFeedback(feedbackType: String, feedbackDescription: String) {
val mapboxNavigation = MapboxNavigationApp.waitUntilInitialized()
mapboxNavigation.postVoiceFeedback(
feedbackSubType = feedbackType,
description = feedbackDescription,
screenshot = "",
) { result ->
// The result contains the feedbackId for tracking purposes
// Optional: Store this feedbackId to close the feedback loop with users
Log.d("VoiceFeedbackViewModel", "feedbackId: ${result.feedbackId}")
}
}
MapboxNavigation.onDestroy; feedback is tied to the provided location/time when FeedbackMetadata is provided, otherwise when postVoiceFeedback is invoked.This example includes a complete Android application integrating Feedback Agent.
Microphone permission
The Feedback Agent requires microphone permission to be able to listen to the user. The application must request the permission before the user first attempts to speak with the assistant. If the permission is not granted, the assistant will not be able to listen to the user.