Android Driver SDK 4.0 Migration Guide

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 to 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:

  1. Obtain a Navigator object from the NavigationApi.

        this, // Activity
        new NavigationApi.NavigatorListener() {
          public void onNavigatorReady(Navigator navigator) {
            // Keep a reference to the Navigator (used to configure and start nav)
            this.navigator = navigator;
  2. Create a DriverContext object, populating the required fields.

    DriverContext driverContext = DriverContext.builder(application)
  3. Use the DriverContext object to initialize the *DriverApi.

    RidesharingDriverApi ridesharingDriverApi = RidesharingDriverApi.createInstance(driverContext);
  4. Obtain the NavigationVehicleReporter from the API object. *VehicleReporter extends NavigationVehicleReporter.

    RidesharingVehicleReporter vehicleReporter = ridesharingDriverApi.getRidesharingVehicleReporter();

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:

RidesharingVehicleReporter reporter = ...;


To update the reporting interval, use RidesharingVehicleReporter.setLocationReportingInterval(long, TimeUnit).

When the driver's shift is finished, disable location updates and mark the vehicle as offline by calling NavigationVehicleReporter.disableLocationTracking().

Setting the vehicle state on the server

In earlier versions, you would use the FleetEngine object to set the vehicle state. In Driver SDK v4, use the RidesharingVehicleReporter object to set the vehicle state:

RidesharingVehicleReporter reporter = ...;


To set the vehicle state to OFFLINE, call RidesharingVehicleReporter.disableLocationTracking(). Errors updating the vehicle state are propagated using the optionally provided StatusListener set in the DriverContext.

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. */
  public void updateStatus(
      StatusLevel statusLevel, StatusCode statusCode, String statusMsg) {
    // Status handling stuff goes here.
    // StatusLevel may be DEBUG, INFO, WARNING, or ERROR.

Authenticating with AuthTokenFactory

AuthTokenFactory now has only one method, getToken(), which takes AuthTokenContext as the parameter. ServiceType has been deprecated. You now only need to get a claim for the included vehicle ID, rather than relying on ServiceType.

class JsonAuthTokenFactory implements AuthTokenFactory {
  private String token;  // initially null
  private long expiryTimeMs = 0;

  // This method is called on a thread whose only responsibility is to send
  // location updates. Blocking is OK, but just know that no location updates
  // can occur until this method returns.
  public String getToken(AuthTokenContext authTokenContext) {
    if (System.currentTimeMillis() > expiryTimeMs) {
      // The token has expired, go get a new one.
    return token;

  private void fetchNewToken(String vehicleId) {
    String url = "https://yourauthserver.example/token/" + vehicleId;

    try (Reader r = new InputStreamReader(new URL(url).openStream())) { obj
      token = obj.get("Token").getAsString();
      expiryTimeMs = obj.get("TokenExpiryMs").getAsLong();

      // The expiry time could be an hour from now, but just to try and avoid
      // passing expired tokens, we subtract 10 minutes from that time.
      expiryTimeMs -= 10 * 60 * 1000;
    } catch (IOException e) {
      // It's OK to throw exceptions here. The StatusListener you passed to
      // create the DriverContext class is notified, and passes along the failed
      // update warning.
      throw new RuntimeException("Could not get auth token", e);