准备好车辆
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本部分介绍了如何让车辆为预定任务做好准备。您必须先完成以下每个步骤,然后后端才能将车辆与任务相匹配。
设置监听器
由于 Driver SDK 在后台执行操作,因此请使用 DriverStatusListener
在发生某些事件(例如错误、警告或调试消息)时触发通知。错误可能是暂时性的(例如 BACKEND_CONNECTIVITY_ERROR
),也可能会导致位置信息更新永久停止。例如,如果您收到 VEHICLE_NOT_FOUND
错误,则表示存在配置错误。
以下示例展示了 DriverStatusListener
实现:
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());
启用位置信息更新
获得 *VehicleReporter
实例后,请按以下方式启用位置信息更新:
Java
DeliveryVehicleReporter reporter = ...;
reporter.enableLocationTracking();
Kotlin
val reporter = ...
reporter.enableLocationTracking()
(可选)设置更新间隔
默认情况下,Driver SDK 会每隔 10 秒发送一次位置更新。每次位置信息更新也表示车辆处于联网状态。您可以使用 reporter.setLocationReportingInterval(long, TimeUnit)
更改此间隔。支持的最小更新间隔为 5 秒。提高更新频率可能会导致请求速度变慢并出现错误。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-09-10。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-10。"],[[["\u003cp\u003eBefore tasks can be assigned, vehicles must be prepared by completing setup steps that enable communication with the backend system.\u003c/p\u003e\n"],["\u003cp\u003eA \u003ccode\u003eDriverStatusListener\u003c/code\u003e is implemented to receive notifications regarding the vehicle's status, including errors, warnings, and debug messages.\u003c/p\u003e\n"],["\u003cp\u003eLocation updates are enabled using the \u003ccode\u003eenableLocationTracking()\u003c/code\u003e method of a \u003ccode\u003e*VehicleReporter\u003c/code\u003e instance, ensuring the backend knows the vehicle's position.\u003c/p\u003e\n"],["\u003cp\u003eOptionally, the frequency of location updates can be customized, but it's recommended to keep it at the default 10-second interval or above to avoid performance issues.\u003c/p\u003e\n"]]],[],null,[]]