mapbox / mapbox/mapbox-navigation-android
Listen for Voice Guidance Muted Changes
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 651
- Forks
- 321
- PR merge metrics
- No merged PRs in 30d
Description
**Android API: 29**
**Mapbox Navigation SDK version: 1.5.1**
I'm trying to get my application to persist whether or not the voice guidance is muted. However, there is no organic way to detect when voice guidance changes from being muted to unmuted or vice versa.
The only way, that I've found, to detect this is to use `navigationView.retrieveSoundButton().addOnClickListener` to trigger when the button has been pressed, indicating a change whether or not voice guidance is muted, and then use `navigationView.isVoiceGuidanceMuted()` to get its updated value. This, however, does not always work. Sometimes the call to `navigationView.isVoiceGuidanceMuted()` does not reflect the new value. I suspect this is because the `OnClickListener` is being called too early. So the final code would look something like this
```java
navigationView.retrieveSoundButton().addOnClickListener(v -> {
handler.postDelayed(() -> {
muteVoiceGuidance = navigationView.isVoiceGuidanceMuted();
prefs.edit().putBoolean("muteVoiceGuidance", muteVoiceGuidance).apply();
Log.v("MapBox", "MuteVoiceGuidance: " + muteVoiceGuidance);
}, 250);
});
```
and then starting navigation like this:
```java
NavigationViewOptions options = NavigationViewOptions.builder(this)
...
.muteVoiceGuidance(muteVoiceGuidance)
.build();
navigationView.startNavigation(options);
```
## Suggestion
Add a method `void addVoiceGuidanceMuteChangeListener(VoiceGuidanceMuteChangeListener listener)` to `NavigationView` where `VoiceGuidanceMuteChangeListener` could be defined as:
```java
@FunctionalInterface
public interface VoiceGuidanceMuteChangeListener {
void onVoiceGuidanceMuteChange(boolean isVoiceGuidanceMuted);
}
```
---
If there is another way to achieve this, then I apologize for the inconvenience.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at NavigationView's sound-button handling and the isVoiceGuidanceMuted() state, then trace how NavigationViewOptions.muteVoiceGuidance is applied when navigation starts. Done means callers can reliably receive the updated mute value whenever voice guidance changes in either direction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100