AI-generated Key Takeaways
-
Before using the Driver SDK, you must initialize both the Navigation SDK and the Driver SDK.
-
To begin, obtain a
Navigatorobject from theNavigationApiand create aDriverContextobject, ensuring your Google Cloud Project ID is included. -
Initialize the
*DriverApiusing theDriverContext, and obtain theDeliveryVehicleReporterfrom it. -
Note that the Driver SDK uses SSL/TLS for secure communication, and you might require a
SecurityProviderpatch for older Android versions.
Before using the Driver SDK, you must first initialize the Navigation SDK and Driver SDK following these steps:
Obtain a
Navigatorobject from theNavigationApi.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 } }, )Create a
DriverContextobject, populating the required fields. To initialize theDriverContextobject, you must enter the Project ID of your Google Cloud Project as theproviderId. For information on setting up the Google Cloud Project, see Create your Fleet Engine project.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()Use the
DriverContextobject to initialize the*DriverApi.DeliveryDriverApi driverApi = DeliveryDriverApi.createInstance(driverContext);Obtain the
DeliveryVehicleReporterfrom the API object. (DeliveryVehicleReporterextendsNavigationVehicleReporter.)DeliveryVehicleReporter vehicleReporter = driverApi.getDeliveryVehicleReporter();
Notes on SSL/TLS
Internally, the Driver SDK implementation uses
SSL/TLS to communicate securely with the Fleet Engine service. Android API
versions 23 or
earlier may require a SecurityProvider patch to communicate with the
server. For more information about working with SSL in Android, see
Security GMS Provider.
The article also contains code samples for patching the security provider.