1package com.navigine.examples
3import com.navigine.idl.java.*
6 * NavigineSDK usage example for Kotlin
7 * Demonstrates SDK initialization and access to various managers
9class NavigineSdkExample {
11 private var sdk: NavigineSdk? = null
12 private var locationManager: LocationManager? = null
13 private var navigationManager: NavigationManager? = null
14 private var zoneManager: ZoneManager? = null
15 private var routeManager: RouteManager? = null
16 private var asyncRouteManager: AsyncRouteManager? = null
17 private var notificationManager: NotificationManager? = null
18 private var measurementManager: MeasurementManager? = null
19 private var locationListManager: LocationListManager? = null
20 private var storageManager: StorageManager? = null
21 private var mqttSession: MqttSession? = null
28 * SDK initialization and basic parameter setup
30 private fun initializeSdk() {
32 // [kotlin_NavigineSdk_getInstance]
34 sdk = NavigineSdk.getInstance()
35 // [kotlin_NavigineSdk_getInstance]
37 // [kotlin_NavigineSdk_getVersion]
39 println("Navigine SDK Version: ${NavigineSdk.getVersion()}")
40 // [kotlin_NavigineSdk_getVersion]
42 // [kotlin_NavigineSdk_getDeviceId]
44 println("Device ID: ${NavigineSdk.getDeviceId()}")
45 // [kotlin_NavigineSdk_getDeviceId]
47 // [kotlin_NavigineSdk_getRelativeTime]
49 println("Relative Time: ${NavigineSdk.getRelativeTime()}")
50 // [kotlin_NavigineSdk_getRelativeTime]
52 // [kotlin_NavigineSdk_setUserHash]
53 // Set user hash (authorization token)
54 sdk?.setUserHash("XXXX-XXXX-XXXX-XXXX")
55 // [kotlin_NavigineSdk_setUserHash]
57 // [kotlin_NavigineSdk_setServer]
58 // Set server URL (optional)
59 sdk?.setServer("https://custom.navigine.com")
60 // [kotlin_NavigineSdk_setServer]
62 // Initialize managers
65 } catch (e: Exception) {
66 System.err.println("SDK initialization error: ${e.message}")
71 * Initialize all SDK managers
73 private fun initializeManagers() {
74 sdk?.let { sdkInstance ->
75 // [kotlin_NavigineSdk_getLocationManager]
76 // Get LocationManager for working with locations
77 locationManager = sdkInstance.locationManager
78 locationManager?.let {
79 println("LocationManager successfully initialized")
81 // [kotlin_NavigineSdk_getLocationManager]
83 // [kotlin_NavigineSdk_getNavigationManager]
84 // Get NavigationManager for navigation
85 locationManager?.let { locationManager ->
86 navigationManager = sdkInstance.getNavigationManager(locationManager)
87 navigationManager?.let {
88 println("NavigationManager successfully initialized")
91 // [kotlin_NavigineSdk_getNavigationManager]
93 // [kotlin_NavigineSdk_getZoneManager]
94 // Get ZoneManager for working with zones
95 navigationManager?.let { navigationManager ->
96 zoneManager = sdkInstance.getZoneManager(navigationManager)
98 println("ZoneManager successfully initialized")
101 // [kotlin_NavigineSdk_getZoneManager]
103 // [kotlin_NavigineSdk_getRouteManager]
104 // Get RouteManager for building routes
105 locationManager?.let { locationManager ->
106 navigationManager?.let { navigationManager ->
107 routeManager = sdkInstance.getRouteManager(locationManager, navigationManager)
109 println("RouteManager successfully initialized")
113 // [kotlin_NavigineSdk_getRouteManager]
115 // [kotlin_NavigineSdk_getAsyncRouteManager]
116 // Get AsyncRouteManager for async route operations
117 locationManager?.let { locationManager ->
118 navigationManager?.let { navigationManager ->
119 asyncRouteManager = sdkInstance.getAsyncRouteManager(locationManager, navigationManager)
120 asyncRouteManager?.let {
121 println("AsyncRouteManager successfully initialized")
125 // [kotlin_NavigineSdk_getAsyncRouteManager]
127 // [kotlin_NavigineSdk_getNotificationManager]
128 // Get NotificationManager for notifications
129 locationManager?.let { locationManager ->
130 notificationManager = sdkInstance.getNotificationManager(locationManager)
131 notificationManager?.let {
132 println("NotificationManager successfully initialized")
135 // [kotlin_NavigineSdk_getNotificationManager]
137 // [kotlin_NavigineSdk_getMeasurementManager]
138 // Get MeasurementManager for measurements
139 locationManager?.let { locationManager ->
140 measurementManager = sdkInstance.getMeasurementManager(locationManager)
141 measurementManager?.let {
142 println("MeasurementManager successfully initialized")
145 // [kotlin_NavigineSdk_getMeasurementManager]
147 // [kotlin_NavigineSdk_getLocationListManager]
148 // Get LocationListManager for location list operations
149 locationListManager = sdkInstance.locationListManager
150 locationListManager?.let {
151 println("LocationListManager successfully initialized")
153 // [kotlin_NavigineSdk_getLocationListManager]
155 // [kotlin_NavigineSdk_getStorageManager]
156 // Get StorageManager for working with storages
157 storageManager = sdkInstance.storageManager
158 storageManager?.let {
159 println("StorageManager successfully initialized")
161 // [kotlin_NavigineSdk_getStorageManager]
163 // [kotlin_NavigineSdk_getMqttSession]
164 // Get MqttSession for publishing position data via MQTT
165 navigationManager?.let { navigationManager ->
166 mqttSession = sdkInstance.getMqttSession(navigationManager)
168 println("MqttSession successfully initialized")
171 // [kotlin_NavigineSdk_getMqttSession]
176 * Get information about current SDK state
179 println("=== Navigine SDK Information ===")
180 println("SDK Version: ${NavigineSdk.getVersion()}")
181 println("Device ID: ${NavigineSdk.getDeviceId()}")
182 println("Relative Time: ${NavigineSdk.getRelativeTime()}")
183 println("LocationManager: ${if (locationManager != null) "available" else "unavailable"}")
184 println("NavigationManager: ${if (navigationManager != null) "available" else "unavailable"}")
185 println("ZoneManager: ${if (zoneManager != null) "available" else "unavailable"}")
186 println("RouteManager: ${if (routeManager != null) "available" else "unavailable"}")
187 println("AsyncRouteManager: ${if (asyncRouteManager != null) "available" else "unavailable"}")
188 println("NotificationManager: ${if (notificationManager != null) "available" else "unavailable"}")
189 println("MeasurementManager: ${if (measurementManager != null) "available" else "unavailable"}")
190 println("LocationListManager: ${if (locationListManager != null) "available" else "unavailable"}")
191 println("StorageManager: ${if (storageManager != null) "available" else "unavailable"}")
192 println("MqttSession: ${if (mqttSession != null) "available" else "unavailable"}")
196 * Demonstrate usage of all managers
198 fun demonstrateManagersUsage() {
199 println("=== Manager Usage Demonstration ===")
201 // LocationManager usage example
202 locationManager?.let {
203 println("LocationManager ready for location operations")
204 // Add code here for loading locations, working with them, etc.
207 // NavigationManager usage example
208 navigationManager?.let {
209 println("NavigationManager ready for positioning")
210 // Add code here for getting position, setting up listeners, etc.
213 // ZoneManager usage example
215 println("ZoneManager ready for zone operations")
216 // Add code here for setting up zones, handling enter/exit events, etc.
219 // RouteManager usage example
221 println("RouteManager ready for route building")
222 // Add code here for building routes, setting destination points, etc.
225 // AsyncRouteManager usage example
226 asyncRouteManager?.let {
227 println("AsyncRouteManager ready for async route operations")
228 // Add code here for creating routing sessions, etc.
231 // NotificationManager usage example
232 notificationManager?.let {
233 println("NotificationManager ready for notifications")
234 // Add code here for setting up beacon notifications, etc.
237 // MeasurementManager usage example
238 measurementManager?.let {
239 println("MeasurementManager ready for measurements")
240 // Add code here for managing measurement generators, etc.
243 // LocationListManager usage example
244 locationListManager?.let {
245 println("LocationListManager ready for location list operations")
246 // Add code here for getting available locations list, etc.
249 // StorageManager usage example
250 storageManager?.let {
251 println("StorageManager ready for storage operations")
252 // Add code here for creating storages, managing data, etc.
255 // MqttSession usage example
257 println("MqttSession ready for publishing position data via MQTT")
258 // Add code here for connecting to MQTT broker, publishing positions, etc.
263 * Demonstrate Kotlin features usage
265 fun demonstrateKotlinFeatures() {
266 println("=== Kotlin Features Demonstration ===")
268 // Using let for safe calls
269 sdk?.let { sdkInstance ->
270 sdkInstance.setUserHash("YYYY-YYYY-YYYY-YYYY")
271 println("User hash updated")
274 // Using run for code block execution
277 "version" to NavigineSdk.getVersion(),
278 "deviceId" to NavigineSdk.getDeviceId(),
279 "relativeTime" to NavigineSdk.getRelativeTime()
282 println("SDK Information: $sdkInfo")
284 // Using with for object operations
285 with(locationManager) {
287 println("LocationManager available for operations")
288 // Call LocationManager methods here
292 // Using apply for object configuration
294 setUserHash("ZZZZ-ZZZZ-ZZZZ-ZZZZ")
295 setServer("https://custom.navigine.com")
297 println("SDK settings updated")
301 * Main function for demonstration
305 fun main(args: Array<String>) {
306 val example = NavigineSdkExample()
307 example.printSdkInfo()
308 example.demonstrateManagersUsage()
309 example.demonstrateKotlinFeatures()