לפני שמשתמשים ב-Driver SDK, צריך קודם להפעיל את Navigation SDK ואת Driver SDK לפי השלבים הבאים:
מקבלים אובייקט
Navigatorמ-NavigationApi.Java
NavigationApi.getNavigator( this, // Activity new NavigationApi.NavigatorListener() { @Override public void onNavigatorReady(Navigator navigator) { // Keep a reference to the Navigator (used to configure and start nav) this.navigator = navigator; } } );Kotlin
NavigationApi.getNavigator( this, // Activity object : NavigatorListener() { override fun onNavigatorReady(navigator: Navigator) { // Keep a reference to the Navigator (used to configure and start nav) this@myActivity.navigator = navigator } }, )יוצרים אובייקט
DriverContextוממלאים את שדות החובה. כדי להפעיל את האובייקטDriverContext, צריך להזין את מזהה הפרויקט של פרויקט בענן ב-Google בתורproviderId. מידע על הגדרת פרויקט בענן של Google זמין במאמר יצירת פרויקט Fleet Engine.Java
DriverContext driverContext = DriverContext.builder(application) .setProviderId(providerId) .setVehicleId(vehicleId) .setAuthTokenFactory(authTokenFactory) .setNavigator(navigator) .setRoadSnappedLocationProvider( NavigationApi.getRoadSnappedLocationProvider(application)) .build();Kotlin
val driverContext = DriverContext.builder(application) .setProviderId(providerId) .setVehicleId(vehicleId) .setAuthTokenFactory(authTokenFactory) .setNavigator(navigator) .setRoadSnappedLocationProvider(NavigationApi.getRoadSnappedLocationProvider(application)) .build()משתמשים באובייקט
DriverContextכדי לאתחל את*DriverApi.DeliveryDriverApi driverApi = DeliveryDriverApi.createInstance(driverContext);מקבלים את ה-
DeliveryVehicleReporterמהאובייקט של ה-API. (DeliveryVehicleReporterמרחיב אתNavigationVehicleReporter.)DeliveryVehicleReporter vehicleReporter = driverApi.getDeliveryVehicleReporter();
הערות לגבי SSL/TLS
באופן פנימי, ההטמעה של Driver SDK משתמשת ב-SSL או ב-TLS כדי לתקשר באופן מאובטח עם שירות Fleet Engine. בגרסאות 23 ומטה של Android API, יכול להיות שצריך תיקון SecurityProvider כדי לתקשר עם השרת. למידע נוסף על עבודה עם SSL ב-Android, ראו ספק GMS לאבטחה.
במאמר יש גם דוגמאות קוד לתיקון ספק האבטחה.