使用 Driver SDK 前,請先按照下列步驟初始化 Navigation SDK 和 Driver SDK:
從
NavigationApi取得Navigator物件。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 Cloud 雲端專案的專案 ID做為providerId。如要瞭解如何設定 Google Cloud 雲端專案,請參閱「建立 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);從 API 物件取得
DeliveryVehicleReporter。(DeliveryVehicleReporter擴充NavigationVehicleReporter。)DeliveryVehicleReporter vehicleReporter = driverApi.getDeliveryVehicleReporter();
SSL/TLS 注意事項
在內部,Driver SDK 實作會使用 SSL/TLS 與 Fleet Engine 服務安全通訊。Android API 23 以下版本可能需要 SecurityProvider 修補程式,才能與伺服器通訊。如要進一步瞭解如何在 Android 中使用 SSL,請參閱「安全性 GMS 供應商」。此外,這篇文章也提供修補安全性供應商的程式碼範例。