Getting Started
Use this guide to set up the Android application for Offline Navigation by adding the SDK, configuring Android permissions, applying runtime behavior, and initializing Maps and NBNavigation in the correct order.
Install the SDK
Add Navigation Android SDK 3.0.1 to the application module. The AAR transitively supplies the verified Maps SDK version used by offline navigation. Do not force a different Maps SDK version unless NextBillion.ai Support explicitly instructs you to do so.
Kotlin DSL
Groovy DSL
If NextBillion.ai provides your organization with a private Maven repository, add that repository alongside mavenCentral() using the URL and read-only credentials supplied for your deployment. Store those credentials in the user-level Gradle properties file or CI secrets. Application consumers do not need the centralUsername or centralToken publishing credentials used by the SDK release pipeline.
Configure permissions
Declare only the permissions required by the features that the application uses. Catalog synchronization and regional downloads require network access but do not require location permission. Continuous turn-by-turn navigation normally uses location and a location-type foreground service.
Manifest Declarations
Permission Requirements
| Permission | Required when | Runtime handling |
|---|---|---|
INTERNET | Catalog sync, regional download, online routing | Manifest only |
ACCESS_NETWORK_STATE | TTL refresh, network policy, SMART routing | Manifest only |
COARSE / FINE LOCATION | Current-position region search or navigation | Request in context; precise navigation normally needs FINE |
FOREGROUND_SERVICE | A foreground navigation service is used | Manifest only |
FOREGROUND_SERVICE_LOCATION | Location foreground service on API 34+ | Manifest; location runtime permission must already be granted |
POST_NOTIFICATIONS | Navigation notifications on API 33+ | Request at runtime before the navigation flow when possible |
Runtime Rules
-
Request location permission only when the user selects a feature that needs location. Downloading offline data by
regionIddoes not require location permission. -
On Android 12 and later, request
COARSEandFINEtogether when the navigation experience needs precise location. Continue with reduced functionality or stop the flow if the user grants only an approximate location. -
On Android 13 and later,
POST_NOTIFICATIONSis not required to start a foreground service, but a denied permission prevents normal display of the navigation notification in the notification drawer. -
Starting with Android 14 (API level 34), applications running a location-based foreground service must declare the
FOREGROUND_SERVICE_LOCATIONpermission in their manifest. Users must also turn on system location services and grant eitherACCESS_COARSE_LOCATIONorACCESS_FINE_LOCATIONbefore navigation starts. Note that precise turn-by-turn guidance typically requiresACCESS_FINE_LOCATION. Since location access is treated as a "while-in-use" permission, initiate the navigation foreground service while an “Activity” is actively visible on screen.ACCESS_BACKGROUND_LOCATIONis not necessary for standard visible starts, and is only needed if your application explicitly launches or retrieves location updates from the background where platform policies permit. -
The Navigation AAR declares its navigation service and location foreground-service type. Do not redeclare the SDK service unless a documented manifest override is required.
Android references: notification runtime permission and location foreground-service requirements.
Configure runtime behavior
Configure the route mode and download network policy before users start offline routing or region downloads. Offline-capable apps should usually switch from the default online-only behavior to a mode such as SMART, then keep the selected download policy consistent when updating runtime configuration.
Runtime configuration applies to the current application process. Reapply the intended route mode and download policy during application startup before opening offline navigation screens.
Initialize Maps during app startup
Initialize the Maps SDK first in your custom application. If Maps is already initialized, do not initialize it again with a different access key, tile server, or CDN. Please note that offline maps require NGLTomTom.
Initialize Offline Navigation
Follow the below steps to initialize offline navigation successfully:
-
Call NBNavigation.initialize() after Nextbillion.(@NonNull Context context, @Nullable String apiKey) is called.
-
Initialization is process-wide, consequently, concurrent calls are coalesced into the same operation.
-
After initialization succeeds, a subsequent initialize() call returns immediately without shutting down or restarting the engine.
Application code should still manage state centrally through an application-scoped Repository or Manager.
syncRegions() also protects the default engine with automatic initialization and waits for any initialization already in progress. Production applications should still call initialize() explicitly so they can handle errors and readiness before opening the offline screen.
Callback threading and state handling
Native and network completion callbacks are posted to the main thread. Parameter validation failures and some immediate results may be returned synchronously. Do not assume that a callback will always occur after the current call stack returns.
Engine shutdown
Do not call NBNavigation.shutdown() when a normal Activity or Fragment is destroyed or when one navigation session ends.
Shut it down only when the process explicitly disables the entire offline capability. Note that a shutdown does not delete data. Call initialize() again before subsequent use.
Recommended call sequence
Use the following recommended call sequence:
-
Initialize the Maps SDK with the
TomTomtile server in application. -
Call NBNavigation.initialize() to initialize offline navigation.
-
Read the local catalogs first for immediate display, then synchronize with
AUTOand refresh the list. -
Download the region by
regionId, and observerouteNetworkandmapTileprogress. -
Set RouteMode, then continue using NBNavigation.fetchRoute() and the existing navigation screens.