Android 驱动程序 SDK 4.0 迁移指南
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 版 Driver SDK 4.0 版要求您更新代码以执行某些操作。本指南概述了相关变更以及您需要执行哪些操作才能迁移代码。
软件包名称变更
软件包名称已从 com.google.android.libraries.ridesharing.driver
更改为 com.google.android.libraries.mapsplatform.transportation.driver
。请更新代码中的引用。
初始化 SDK
在之前的版本中,您需要先初始化 Navigation SDK,然后获取对 FleetEngine
类的引用。在 Driver SDK v4 中,按如下方式初始化 SDK:
从 NavigationApi
获取 Navigator
对象。
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;
}
}
);
创建一个 DriverContext
对象,并填充必需的字段。
DriverContext driverContext = DriverContext.builder(application)
.setProviderId(providerId)
.setVehicleId(vehicleId)
.setAuthTokenFactory(authTokenFactory)
.setNavigator(navigator)
.setRoadSnappedLocationProvider(
NavigationApi.getRoadSnappedLocationProvider(application))
.build();
使用 DriverContext
对象初始化 *DriverApi
。
从 API 对象获取 NavigationVehicleReporter
。
*VehicleReporter
扩展了 NavigationVehicleReporter
。
启用和停用位置信息更新
在之前的版本中,您会在获得 FleetEngine
引用后启用位置信息更新。在 Driver SDK v4 中,按如下方式启用位置信息更新:
当司机结束班次时,请通过调用 NavigationVehicleReporter.disableLocationTracking()
停用位置信息更新并将车辆标记为离线。
使用 StatusListener 进行错误报告
ErrorListener
已移除并与 StatusListener
合并,后者可定义如下:
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.
}
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Driver SDK for Android has been updated to version 4.0, requiring code changes for certain operations.\u003c/p\u003e\n"],["\u003cp\u003eThe package name has changed to \u003ccode\u003ecom.google.android.libraries.mapsplatform.transportation.driver\u003c/code\u003e and the SDK initialization process has been revised.\u003c/p\u003e\n"],["\u003cp\u003eLocation updates are now enabled and disabled using the \u003ccode\u003eNavigationVehicleReporter\u003c/code\u003e methods.\u003c/p\u003e\n"],["\u003cp\u003eError reporting is consolidated within \u003ccode\u003eStatusListener\u003c/code\u003e, replacing the previous \u003ccode\u003eErrorListener\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Android Driver SDK 4.0 Migration Guide\n\nThe Driver SDK for Android 4.0 release requires that you update your code\nfor certain operations. This guide outlines the changes and what\nyou'll need to do to migrate your code.\n\nPackage name change\n-------------------\n\nThe package name has changed from\n`com.google.android.libraries.ridesharing.driver` to\n`com.google.android.libraries.mapsplatform.transportation.driver`. Please\nupdate references in your code.\n\nInitializing the SDK\n--------------------\n\nIn earlier versions, you would initialize the Navigation SDK and then obtain\na reference to the `FleetEngine` class. In Driver SDK\nv4, initialize the SDK as follows:\n\n1. Obtain a `Navigator` object from the `NavigationApi`.\n\n NavigationApi.getNavigator(\n this, // Activity\n new NavigationApi.NavigatorListener() {\n @Override\n public void onNavigatorReady(Navigator navigator) {\n // Keep a reference to the Navigator (used to configure and start nav)\n this.navigator = navigator;\n }\n }\n );\n\n2. Create a `DriverContext` object, populating the required fields.\n\n DriverContext driverContext = DriverContext.builder(application)\n .setProviderId(providerId)\n .setVehicleId(vehicleId)\n .setAuthTokenFactory(authTokenFactory)\n .setNavigator(navigator)\n .setRoadSnappedLocationProvider(\n NavigationApi.getRoadSnappedLocationProvider(application))\n .build();\n\n3. Use the `DriverContext` object to initialize the `*DriverApi`.\n\n4. Obtain the `NavigationVehicleReporter` from the API object.\n `*VehicleReporter` extends `NavigationVehicleReporter`.\n\nEnabling and disabling location updates\n---------------------------------------\n\nIn earlier versions, you would enable location updates after obtaining\na `FleetEngine` reference. In Driver SDK v4, enable\nlocation updates as follows:\n\nWhen the driver's shift is finished, disable location updates\nand mark the vehicle as offline by calling `NavigationVehicleReporter.disableLocationTracking()`.\n\nError Reporting with StatusListener\n-----------------------------------\n\n`ErrorListener` has been removed and combined with `StatusListener`,\nwhich may be defined like the following: \n\n class MyStatusListener implements StatusListener {\n /** Called when background status is updated, during actions such as location reporting. */\n @Override\n public void updateStatus(\n StatusLevel statusLevel, StatusCode statusCode, String statusMsg) {\n // Status handling stuff goes here.\n // StatusLevel may be DEBUG, INFO, WARNING, or ERROR.\n // StatusCode may be DEFAULT, UNKNOWN_ERROR, VEHICLE_NOT_FOUND,\n // BACKEND_CONNECTIVITY_ERROR, or PERMISSION_DENIED.\n }\n }"]]