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 の操作について詳しくは、Security GMS プロバイダをご覧ください。この記事には、セキュリティ プロバイダにパッチを適用するためのコードサンプルも含まれています。