تجهيز المركبة
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يوضّح هذا القسم كيفية تجهيز المركبة للمهام المُجدوَلة. يجب إكمال كل خطوة من الخطوات التالية قبل أن تتمكّن الخلفية من مطابقة مركبة بمهمة.
إعداد المستمع
بما أنّ حزمة تطوير البرامج (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 ثوانٍ. قد تؤدي التحديثات المتكررة إلى بطء الطلبات وحدوث أخطاء.
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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,["# Get the vehicle ready\n\nThis section shows how to get the vehicle ready for scheduled tasks. You must\ncomplete each of the following steps before your backend can match a vehicle to\na task.\n\nSet up listener\n---------------\n\nSince the Driver SDK performs actions in the\nbackground, use the `DriverStatusListener` to trigger notifications when certain\nevents occur, such as errors, warnings, or debug messages. Errors can be\ntransient in nature (such as `BACKEND_CONNECTIVITY_ERROR`), or they might\ncause location updates to stop permanently. For example, if you receive a\n`VEHICLE_NOT_FOUND` error, it indicates a configuration error.\n\nThe following example shows a `DriverStatusListener` implementation: \n\n class MyStatusListener implements DriverStatusListener {\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, @Nullable Throwable cause) {\n // Existing implementation\n\n if (cause != null && cause instanceof StatusRuntimeException) {\n if (Status.NOT_FOUND.getCode().equals(cause.getStatus().getCode())) {\n // NOT_FOUND gRPC exception thrown by Fleet Engine.\n }\n }\n }\n }\n\n DriverContextBuilder.setDriverStatusListener(new MyStatusListener());\n\nEnable location updates\n-----------------------\n\nOnce you have a `*VehicleReporter` instance, enable location updates as follows: \n\n### Java\n\n DeliveryVehicleReporter reporter = ...;\n\n reporter.enableLocationTracking();\n\n### Kotlin\n\n val reporter = ...\n\n reporter.enableLocationTracking()\n\n### (Optional) Set the update interval\n\nBy default, the Driver SDK sends location updates at 10-second intervals. Each\nlocation update also indicates that the vehicle is online. You can change this\ninterval with\n`reporter.setLocationReportingInterval(long, TimeUnit)`. The minimum supported\nupdate interval is 5 seconds. More frequent updates may result in slower\nrequests and errors."]]