AI-generated Key Takeaways
-
Driver SDK for Android v4 requires code updates for operations like package name and initialization.
-
The package name has changed to
com.google.android.libraries.mapsplatform.transportation.driver
. -
SDK initialization now involves obtaining a
Navigator
, creating aDriverContext
, and initializing the*DriverApi
. -
Location updates are enabled and disabled using the
NavigationVehicleReporter
methods. -
Error reporting is now handled through the
StatusListener
which replaces theErrorListener
.
The Driver SDK for Android 4.0 release requires that you update your code for certain operations. This guide outlines the changes and what you'll need to do to migrate your code.
Package name change
The package name has changed from
com.google.android.libraries.ridesharing.driver
to
com.google.android.libraries.mapsplatform.transportation.driver
. Please
update references in your code.
Initializing the SDK
In earlier versions, you would initialize the Navigation SDK and then obtain
a reference to the FleetEngine
class. In Driver SDK
v4, initialize the SDK as follows:
Obtain a
Navigator
object from theNavigationApi
.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; } } );
Create a
DriverContext
object, populating the required fields.DriverContext driverContext = DriverContext.builder(application) .setProviderId(providerId) .setVehicleId(vehicleId) .setAuthTokenFactory(authTokenFactory) .setNavigator(navigator) .setRoadSnappedLocationProvider( NavigationApi.getRoadSnappedLocationProvider(application)) .build();
Use the
DriverContext
object to initialize the*DriverApi
.Obtain the
NavigationVehicleReporter
from the API object.*VehicleReporter
extendsNavigationVehicleReporter
.
Enabling and disabling location updates
In earlier versions, you would enable location updates after obtaining
a FleetEngine
reference. In Driver SDK v4, enable
location updates as follows:
When the driver's shift is finished, disable location updates
and mark the vehicle as offline by calling NavigationVehicleReporter.disableLocationTracking()
.
Error Reporting with StatusListener
ErrorListener
has been removed and combined with StatusListener
,
which may be defined like the following:
class MyStatusListener implements StatusListener {
/** Called when background status is updated, during actions such as location reporting. */
@Override
public void updateStatus(
StatusLevel statusLevel, StatusCode statusCode, String statusMsg) {
// Status handling stuff goes here.
// StatusLevel may be DEBUG, INFO, WARNING, or ERROR.
// StatusCode may be DEFAULT, UNKNOWN_ERROR, VEHICLE_NOT_FOUND,
// BACKEND_CONNECTIVITY_ERROR, or PERMISSION_DENIED.
}
}