Android
Introduction
This tutorial will walk you through the step-by-step process of integrating the Telenav SDK (TASDK) into your Android application. TASDK is a comprehensive solution designed to provide all the essential navigation features you need, including advanced routing algorithms, real-time guidance, precise positioning, ADAS (Advanced Driver Assistance Systems) integration, voice assistance, high-performance map rendering, and customizable UI components. By following this tutorial, you will gain a clear understanding of how to set up and utilize TASDK, enabling you to implement a fully functional basic navigation feature in your application by the end of the guide.
Prerequisites:
- Basic knowledge of Android development using Kotlin or Java.
- Android Studio installed.
- An API key and API secret for the TASDK.
System Requirements
- Android device with ARM or x86_64 architecture.
- Android 6.0 (API 23) or above.
- Java 8 or higher.
- Kotlin 1.6.10 or higher.
- NDK versions r15c or r19c supported.
Add the following to the android
block in your build.gradle
file to ensure compatibility:
Get Started
Step 1: Set Up Your Project
1. Add TASDK Dependency
Open your Android Studio project and add the following dependencies to your project's build.gradle file:
Sync your project by clicking Sync Now.
2. Add Required Permissions:
Add the following permissions for location access in your AndroidManifest.xml
:
Step 2: Initialize TASDK
1. Configure SDK Options:
ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permission required.
2. Set Up MapView:
Declare Mapview on the target layout.
3. Initialize MapView:
Build and Run your application on Device.Now you should be able to see the map, it will use the default map styles the SDK is shipped with. pan/zoom operations are supported. Also, there are other subset APIs exposed, including: setZoomLevel and followVehicle.
Step 3: Get Direction
1. Initialize a direction client.
2. Create a routing request
3. Create a request task and execute
Step 4: Work with DriveSession
Drive session is the most important component of our SDK. It serves map-matching, navigation, alerts and other important services.
As with our other service components, the user creates the drive session instances via a factory.
By default, some of its services like the position service will automatically run once the drive session instance been created. If you don't want some services, you can disable them when drive session initialize.
There is another important concept named event hub which using for communicating between each service and the SDK user during runtime, SDK user can get the event hub instance with getEventHub function call:
Start navigation
start a new navigation session with startNavigation function call
During an active navigation session, the SDK will broadcast navigation signals (at 1Hz frequenct) informing each other on the status of current navigation session, following information included:
- distance to turn
- turn type(icon) of current step
- next street name
- highway EXIT label and other signpost strings(if availible)
- lane patterns(if available)
- junction view image(if available)
- ETA of upcoming stop or destination
After completing the above four steps, you have successfully integrated the TASDK into your Android app. You can now expand its capabilities to provide a full navigation experience.
Enable HDMap
Environment variable setup
In order to receive notifying message from SD navigation SDK correctly, the user needs to specify an port of the machine running SD navigation SDK by HDMap service options.
For avoiding the conflict of ports when more than one client integrates HDMap SDK, SD navigation SDK has a strategy to automatically select a randomized address port of the broker if not set.
The user must not use the randomized port in range of [20000, 20099].
Customize the map UI
Replace default configurations for UI customization
There are different configurations for different oem projects.Client can replace default configurations with oem configurations.Oem configurations must be high priority that other tasdk packages.
Dispose
Lastly, make sure to clean up when the activity lifetime ends: TASDK for Android provides the methods as shown below - to safely release all of its remaining resources.
Troubleshooting
If you encounter any issues, please first ensure that you have reviewed the System Requirements
- I see only blank black map in pure streaming mode: Make sure that API key/API secret and endpoint are valid or Region is set. Or check your network connectivity.
- Custom configs not work : Ensure the oem configurations package with higher priority than other tasdk package.In practices, the local package takes precedence over the remote package. Refer to the (https://developer.android.com/studio/build/dependencies) for detail.
- Get a crash due to onboard data can't access: Verify that the SDK data directory is correctly configured and accessible.