NavigationManager
class NavigationManager : Manager
TestNavigationManager |
The |
Manager for communicating navigation related events with the host.
Navigation apps must use this interface to coordinate with the car system for navigation specific resources such as vehicle cluster and heads-up displays.
When a navigation app receives a user action to start navigating, it should call navigationStarted to indicate it is currently navigating. When the app receives a user action to end navigation or when the destination is reached, navigationEnded should be called.
Navigation apps must also register a NavigationManagerCallback to handle callbacks to onStopNavigation issued by the host.
Summary
Public functions |
|
|---|---|
Boolean |
Returns whether the host supports setting voice assistant capabilities. |
Unit |
Clears the callback for receiving navigation manager events. |
Unit |
Notifies the host that the app has ended active navigation. |
Unit |
Notifies the host that the app has started active navigation. |
Unit |
Sets a callback to start receiving navigation manager events. |
Unit |
@MainThreadSets a callback to start receiving navigation manager events. |
Unit |
@MainThreadSends the voice assistant capabilities and consent state of the navigation app to the host. |
Unit |
@MainThreadSends the destinations, steps, and trip estimates to the host. |
Public functions
canSetVoiceAssistantCapabilities
@ExperimentalCarApi
@RequiresCarApi(value = 9)
fun canSetVoiceAssistantCapabilities(): Boolean
Returns whether the host supports setting voice assistant capabilities.
Third-party navigation apps should call this method before attempting to build or send a NavigationVoiceAssistantCapabilities object, as it is only supported on specific host platforms (e.g., Android Automotive OS).
| Returns | |
|---|---|
Boolean |
|
clearNavigationManagerCallback
@MainThread
fun clearNavigationManagerCallback(): Unit
Clears the callback for receiving navigation manager events.
| Throws | |
|---|---|
java.lang.IllegalStateException |
if navigation is started (see |
navigationEnded
@MainThread
fun navigationEnded(): Unit
Notifies the host that the app has ended active navigation.
Only one app may be actively navigating in the car at any time and ownership is managed by the host. The app must call this method to inform the system that it has ended navigation, for example, in response to the user cancelling navigation or upon reaching the destination.
This method is idempotent.
| Throws | |
|---|---|
java.lang.IllegalStateException |
if the current thread is not the main thread |
navigationStarted
@MainThread
fun navigationStarted(): Unit
Notifies the host that the app has started active navigation.
Only one app may be actively navigating in the car at any time and ownership is managed by the host. The app must call this method to inform the system that it has started navigation in response to user action.
This function can only called if setNavigationManagerCallback has been called with a non-null value. The callback is required so that a signal to stop navigation from the host can be handled using onStopNavigation.
This method is idempotent.
| Throws | |
|---|---|
java.lang.IllegalStateException |
if no navigation manager callback has been set, or if the current thread is not the main thread |
setNavigationManagerCallback
@MainThread
fun setNavigationManagerCallback(callback: NavigationManagerCallback): Unit
Sets a callback to start receiving navigation manager events. Note that the callback events will be executed on the main thread using getMainLooper. To specify the execution thread, use setNavigationManagerCallback.
| Parameters | |
|---|---|
callback: NavigationManagerCallback |
the |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if the current thread is not the main thread |
setNavigationManagerCallback
@MainThread
fun setNavigationManagerCallback(
executor: Executor,
callback: NavigationManagerCallback
): Unit
Sets a callback to start receiving navigation manager events.
| Parameters | |
|---|---|
executor: Executor |
the executor which will be used for invoking the callback |
callback: NavigationManagerCallback |
the |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if the current thread is not the main thread |
setVoiceAssistantCapabilities
@MainThread
@ExperimentalCarApi
@RequiresCarApi(value = 9)
fun setVoiceAssistantCapabilities(
capabilities: NavigationVoiceAssistantCapabilities
): Unit
Sends the voice assistant capabilities and consent state of the navigation app to the host.
This allows the app to dynamically toggle whether the voice assistant can access the active navigation state, and declares the actions and disruptions the app supports.
| Parameters | |
|---|---|
capabilities: NavigationVoiceAssistantCapabilities |
The capabilities and consent state to send to the host. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if the current thread is not the main thread, or if the host does not support voice assistant capabilities |
java.lang.IllegalArgumentException |
if the provided capabilities cannot be serialized |
androidx.car.app.HostException |
if the call is invoked by an app that is not declared as a navigation app in the manifest |
updateTrip
@MainThread
fun updateTrip(trip: Trip): Unit
Sends the destinations, steps, and trip estimates to the host.
The data may be rendered at different places in the car such as the instrument cluster screen or the heads-up display.
This method should only be invoked once the navigation app has called navigationStarted, or else the updates will be dropped by the host. Once the app has called navigationEnded or received onStopNavigation it should stop sending updates.
As the location changes, and in accordance with speed and rounded distance changes, the TravelEstimates in the provided Trip should be rebuilt and this method called again. For example, when the next step is greater than 10 kilometers away and the display unit is kilometers, updates should occur roughly every kilometer.
Data provided to the cluster display depends on the vehicle capabilities. In some instances the information may not be shown at all. On some vehicles androidx.car.app.navigation.model.Maneuvers of unknown type may be skipped while on other displays the associated icon may be shown.
| Parameters | |
|---|---|
trip: Trip |
destination, steps, and trip estimates to be sent to the host |
| Throws | |
|---|---|
androidx.car.app.HostException |
if the call is invoked by an app that is not declared as a navigation app in the manifest |
java.lang.IllegalStateException |
if the call occurs when navigation is not started (see |
java.lang.IllegalArgumentException |
if any of the destinations, steps, or trip position is not well formed |