mapbox / mapbox-navigation-android-examples

Other
53 stars 46 forks source link

Update android auto #62

Closed kmadsen closed 2 years ago

kmadsen commented 2 years ago

Features

Navigate with voice commands

Google Play was providing a warning that our app does not handle voice commands. So now you can navigate with audio. To test it with the desktop head unit, use the mic begin command.

./desktop-head-unit
>  mic begin
** speak "Navigate to coffee"

https://user-images.githubusercontent.com/3021882/141598723-e8efab90-ffa8-441c-9544-e54052d5816f.mov

Fixes

Show markers and current location place list map view.

Before After
Screen Shot 2021-11-11 at 4 32 46 PM Screen Shot 2021-11-11 at 4 49 36 PM

Refactor

MapboxNavigationProvider can have issues because a previous version of MapboxNavigation will be destroyed. This results in a common crash "Fatal Exception: java.lang.IllegalStateException: This instance of MapboxNavigation is destroyed."

Instead of accessing MapboxNavigation through MapboxNavigation.retrieve(), this is making it so we can access MapboxNavigation through services with a lifecycle.

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        // Required in order to use `MapboxNavigationApp`
        MapboxNavigationApp.setup(this, MyMapboxNavigationInitializer())

        // Application level services
        MapboxNavigationApp.registerObserver(MyHistoryLifecycleObserver())
        MapboxNavigationApp.registerObserver(MyReplayLifecycleObserver())

        // Setup android auto after you set up MapboxNavigationApp
        MapboxCarApp.setup(this, ExampleCarInitializer())
class MyNavigationInitializer : MapboxNavigationInitializer {
    override fun create(application: Application): NavigationOptions {
        // Allows you to customize `NavigationOptions`
    }
}
class MyHistoryLifecycleObserver : MapboxNavigationObserver {
    private lateinit var history: ExampleHistoryRecorder

    override fun onAttached(mapboxNavigation: MapboxNavigation) {
        history = getKoin().get(ExampleHistoryRecorder::class)
        history.startRecording(mapboxNavigation)
    }

    override fun onDetached(mapboxNavigation: MapboxNavigation?) {
        history.stopAndUploadHistory(mapboxNavigation)
    }
}
Androidbangnv commented 2 years ago

Hi ! How can android desktop head receive mic from computer?