Hướng dẫn di chuyển SDK trình điều khiển Android 4.0

Bản phát hành Driver SDK cho Android 4.0 yêu cầu bạn cập nhật mã cho một số thao tác. Hướng dẫn này trình bày những thay đổi và những việc bạn cần làm để di chuyển mã.

Thay đổi tên gói

Tên gói đã thay đổi từ com.google.android.libraries.ridesharing.driver thành com.google.android.libraries.mapsplatform.transportation.driver. Vui lòng cập nhật các tham chiếu trong mã của bạn.

Khởi chạy SDK

Trong các phiên bản trước, bạn sẽ khởi chạy Navigation SDK rồi lấy tham chiếu đến lớp FleetEngine. Trong Driver SDK phiên bản 4, hãy khởi chạy SDK như sau:

  1. Lấy đối tượng Navigator từ NavigationApi.

    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;
          }
        }
    );
    
  2. Tạo đối tượng DriverContext, điền các trường bắt buộc.

    DriverContext driverContext = DriverContext.builder(application)
        .setProviderId(providerId)
        .setVehicleId(vehicleId)
        .setAuthTokenFactory(authTokenFactory)
        .setNavigator(navigator)
        .setRoadSnappedLocationProvider(
            NavigationApi.getRoadSnappedLocationProvider(application))
        .build();
    
  3. Sử dụng đối tượng DriverContext để khởi chạy *DriverApi.

  4. Lấy NavigationVehicleReporter từ đối tượng API. *VehicleReporter mở rộng NavigationVehicleReporter.

Bật và tắt thông tin cập nhật vị trí

Trong các phiên bản trước, bạn sẽ bật thông tin cập nhật vị trí sau khi lấy tham chiếu FleetEngine. Trong Driver SDK phiên bản 4, hãy bật thông tin cập nhật vị trí như sau:

Khi ca làm việc của tài xế kết thúc, hãy tắt thông tin cập nhật vị trí và đánh dấu xe là ngoại tuyến bằng cách gọi NavigationVehicleReporter.disableLocationTracking().

Error Reporting bằng StatusListener

ErrorListener đã bị xoá và kết hợp với StatusListener. Bạn có thể xác định StatusListener như sau:

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.
  }
}