Tutorials
Navigation SDK’s Android SDK levels For compatibility and optimal performance, ensure that your project adheres to the specified SDK version configurations.
- minSdkVersion 21
- targetSdkVersion 34
- compileSdkVersion 34
When integrating the Play Services location dependency (com.google.android.gms:play-services-location:20.0.0), it's essential to maintain version 20.0.0 or below. Starting from version 21.0.0, breaking changes have been introduced where some classes are now interfaces instead of classes, effective from October 13, 2022.
Add Permissions
To unlock the full capabilities of the Navigation Compose SDK, ensure that your AndroidManifest.xml
file includes the necessary permissions declaration. This step is crucial for enabling seamless functionality across various features and components provided by the SDK.
Setting Up Access Key for NextBillion NavigationView
To enable access to the NextBillion NavigationView within your project, follow these steps:
Update AndroidManifest.xml
Locate the <application>
tag in your project's AndroidManifest.xml file. Add a <provider>
element inside it declaring androidx.startup.InitializationProvider
, responsible for application initialization.
Create AppDataInitStartup Class
Next, create a class named AppDataInitStartup
in your project. This class should implement the Initializer<Boolean>
interface. Within the create
method of this class, perform the initialization tasks for your application. In this example, the initialization task is performed using Nextbillion.getInstance(context, "YOUR-ACCESS-KEY").
Ensure to replace YOUR-ACCESS-KEY
with your actual access key provided by NextBillion.ai.
By following these steps, you have added the code for AppDataInitStartup in your Android project. This code will be executed when the application starts, performing the initialization tasks defined in the create method.
Integrating NextBillion Navigation View into Your App
To seamlessly incorporate the NextBillion NavigationView into your application, follow this simple example utilizing the Compose extension:
This example provides a comprehensive guide on integrating the NextBillion NavigationView into your app. Customize the provided methods as needed to tailor the navigation experience to your application's requirements. NavViewConfig Parameter Description
NavViewConfig
is used to configure all parameters in the navigation process, including setting routes, route event listener, navigation monitoring, and so on. Initialization of this configuration is achieved through a builder pattern:
The parameter configuration and usage are as follows.
Required Parameters
Name | Description |
---|---|
route(DirectionsRoute directionsRoute) | Sets the current navigation route. |
routes(List<DirectionsRoute> directionsRoutes) | Sets the list of navigation routes. The first route in the list corresponds to the primary route set via the route method, while the subsequent routes represent alternative options. |
navigationListener(NavigationListener navigationListener) | Establishes the navigation listener, allowing retrieval of navigation events. If employing NBNavigationView within a custom activity, ensure to finish the activity within the onCancelNavigation callback. |
Optional Parameters
Name | Description |
---|---|
locationLayerRenderMode(int renderMode) | Specifies the render mode for the location layer. The default is RenderMode.GPS . Available values: RenderMode.COMPASS, RenderMode.NORMAL, RenderMode.GPS |
lightThemeResId(Integer lightThemeResId) | Sets the light theme style ID, with the style parent being NavigationViewLight . |
darkThemeResId(Integer darkThemeResId) | Assigns the dark theme style ID, with the style parent being NavigationViewDark . |
shouldSimulateRoute(boolean shouldSimulateRoute) | Enables or disables simulation mode. The default is false . |
waynameChipEnabled(boolean waynameChipEnabled) | Toggles the visibility of the wayname chip. The default is true . |
themeMode(String themeMode) | Configures the navigation theme mode, which can be set as: NavigationConstants.NAVIGATION_VIEW_FOLLOW_SYSTEM_MODE, NavigationConstants.NAVIGATION_VIEW_DARK_MODE, or NavigationConstants.NAVIGATION_VIEW_LIGHT_MODE. The default is NavigationConstants.NAVIGATION_VIEW_FOLLOW_SYSTEM_MODE. |
navConfig(NavEngineConfig navConfig) | Specifies the navigation engine configuration. |
routeListener(RouteListener routeListener) | Registers the route listener to capture navigation route events. |
progressChangeListener(ProgressChangeListener progressChangeListener) | Sets up the listener for navigation progress changes. |
milestoneEventListener(MilestoneEventListener milestoneEventListener) | Configures the milestone event listener. |
milestones(List<Milestone> milestones) | Customizes the milestones. |
instructionListListener(InstructionListListener instructionListListener) | Establishes the instruction list listener. |
speechAnnouncementListener(SpeechAnnouncementListener speechAnnouncementListener) | Sets up the listener for speech announcements. |
By leveraging these parameters, you can fine-tune the behavior and appearance of the NextBillion NavigationView to suit your application's needs.
Example
The following example demonstrates how to configure the parameters using the builder pattern.
In this example, replace primaryRoute, routeList, navigationListener, RenderMode.GPS, R.style.NavigationViewLight, R.style.NavigationViewDark, false, true, NavigationConstants.NAVIGATION_VIEW_FOLLOW_SYSTEM_MODE, navEngineConfig, routeListener, progressChangeListener, milestoneEventListener, customMilestones, instructionListListener, and speechAnnouncementListener with appropriate instances or values according to your application's requirements.