Get the vehicle ready

This section shows how to get the vehicle ready for trips. You must complete each of the following steps before your backend can match a vehicle to a trip.

Set up listener

Since the Driver SDK performs actions in the background, use the DriverStatusListener to trigger notifications when certain events occur, such as errors, warnings, or debug messages. Errors can be transient in nature (such as BACKEND_CONNECTIVITY_ERROR), or they might cause location updates to stop permanently. For example, if you receive a VEHICLE_NOT_FOUND error, it indicates a configuration error.

The following example shows a DriverStatusListener implementation:

class MyStatusListener implements DriverStatusListener {
  /** Called when background status is updated, during actions such as location reporting. */
  @Override
  public void updateStatus(
      StatusLevel statusLevel, StatusCode statusCode, String statusMsg, @Nullable Throwable cause) {
    // Existing implementation

    if (cause != null && cause instanceof StatusRuntimeException) {
      if (Status.NOT_FOUND.getCode().equals(cause.getStatus().getCode())) {
        // NOT_FOUND gRPC exception thrown by Fleet Engine.
      }
    }
  }
}

DriverContextBuilder.setDriverStatusListener(new MyStatusListener());

Enable location updates

After you set up the listener, enable location updates as follows:

Java

RidesharingVehicleReporter reporter = ...;

reporter.enableLocationTracking();

Kotlin

val reporter = ...

reporter.enableLocationTracking()

Set the update interval

By default, the Driver SDK sends location updates at 10-second intervals interval when the vehicle state is ONLINE. You can change this interval with reporter.setLocationReportingInterval(long, TimeUnit). The minimum supported update interval is 5 seconds. More frequent updates may result in slower requests and errors.

Set the vehicle state to online

When you turn on location updates, you can set the vehicle state to ONLINE to make the vehicle available for SearchVehicles queries in Fleet Engine. The Driver SDK sends the updated vehicle state along with the location updates.

You can set the vehicle state directly in the Driver SDK or in the Fleet Engine server. For more information, see Update a Vehicle.

The following examples show how to set the vehicle state to online in the Driver SDK:

Java

RidesharingVehicleReporter reporter = ...;

reporter.enableLocationTracking();
reporter.setVehicleState(VehicleState.ONLINE);

Kotlin

val reporter = ...

reporter.enableLocationTracking()
reporter.setVehicleState(VehicleState.ONLINE)

The StatusListener also reports any errors that occur when updating the vehicle state.

What's next

Set the trip details