เริ่มต้น SDK ของไดรเวอร์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ก่อนใช้ Driver SDK คุณต้องเริ่มต้น
Navigation SDK และ Driver SDK ก่อนโดยทำตามขั้นตอนต่อไปนี้
รับออบเจ็กต์ Navigator
จาก NavigationApi
Java
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;
}
}
);
Kotlin
NavigationApi.getNavigator(
this, // Activity
object : NavigatorListener() {
override fun onNavigatorReady(navigator: Navigator) {
// Keep a reference to the Navigator (used to configure and start nav)
this@myActivity.navigator = navigator
}
},
)
สร้างออบเจ็กต์ DriverContext
โดยป้อนข้อมูลในช่องที่ต้องกรอก หากต้องการ
เริ่มต้นออบเจ็กต์ DriverContext
คุณต้องป้อนรหัสโปรเจ็กต์
ของโปรเจ็กต์ Google Cloud เป็น providerId
ดูข้อมูล
เกี่ยวกับการตั้งค่าโปรเจ็กต์ Google Cloud ได้ที่
สร้างโปรเจ็กต์ Fleet Engine
Java
DriverContext driverContext = DriverContext.builder(application)
.setProviderId(providerId)
.setVehicleId(vehicleId)
.setAuthTokenFactory(authTokenFactory)
.setNavigator(navigator)
.setRoadSnappedLocationProvider(
NavigationApi.getRoadSnappedLocationProvider(application))
.build();
Kotlin
val driverContext =
DriverContext.builder(application)
.setProviderId(providerId)
.setVehicleId(vehicleId)
.setAuthTokenFactory(authTokenFactory)
.setNavigator(navigator)
.setRoadSnappedLocationProvider(NavigationApi.getRoadSnappedLocationProvider(application))
.build()
ใช้ออบเจ็กต์ DriverContext
เพื่อเริ่มต้น *DriverApi
DeliveryDriverApi driverApi = DeliveryDriverApi.createInstance(driverContext);
รับ DeliveryVehicleReporter
จากออบเจ็กต์ API
(DeliveryVehicleReporter
ขยาย NavigationVehicleReporter
)
DeliveryVehicleReporter vehicleReporter = driverApi.getDeliveryVehicleReporter();
หมายเหตุเกี่ยวกับ SSL/TLS
ภายใน การติดตั้งใช้งาน Driver SDK จะใช้
SSL/TLS เพื่อสื่อสารกับบริการ Fleet Engine อย่างปลอดภัย API ของ Android
เวอร์ชัน 23 หรือ
ก่อนหน้าอาจต้องใช้แพตช์ SecurityProvider
เพื่อสื่อสารกับเซิร์ฟเวอร์ ดูข้อมูลเพิ่มเติมเกี่ยวกับการทำงานกับ SSL ใน Android ได้ที่
ผู้ให้บริการ GMS ด้านความปลอดภัย
บทความนี้ยังมีตัวอย่างโค้ดสำหรับการแก้ไขผู้ให้บริการด้านความปลอดภัยด้วย
ขั้นตอนถัดไป
เตรียมรถให้พร้อม
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eBefore using the Driver SDK, you must initialize both the Navigation SDK and the Driver SDK.\u003c/p\u003e\n"],["\u003cp\u003eTo begin, obtain a \u003ccode\u003eNavigator\u003c/code\u003e object from the \u003ccode\u003eNavigationApi\u003c/code\u003e and create a \u003ccode\u003eDriverContext\u003c/code\u003e object, ensuring your Google Cloud Project ID is included.\u003c/p\u003e\n"],["\u003cp\u003eInitialize the \u003ccode\u003e*DriverApi\u003c/code\u003e using the \u003ccode\u003eDriverContext\u003c/code\u003e, and obtain the \u003ccode\u003eDeliveryVehicleReporter\u003c/code\u003e from it.\u003c/p\u003e\n"],["\u003cp\u003eNote that the Driver SDK uses SSL/TLS for secure communication, and you might require a \u003ccode\u003eSecurityProvider\u003c/code\u003e patch for older Android versions.\u003c/p\u003e\n"]]],[],null,["# Initialize the Driver SDK\n\nBefore using the Driver SDK, you must first initialize\nthe Navigation SDK and Driver SDK following these steps:\n\n1. Obtain a `Navigator` object from the `NavigationApi`.\n\n ### Java\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\n ### Kotlin\n\n NavigationApi.getNavigator(\n this, // Activity\n object : NavigatorListener() {\n override fun onNavigatorReady(navigator: Navigator) {\n // Keep a reference to the Navigator (used to configure and start nav)\n this@myActivity.navigator = navigator\n }\n },\n )\n\n2. Create a `DriverContext` object, populating the required fields. To\n initialize the `DriverContext` object, you must enter the **Project ID**\n of your Google Cloud Project as the `providerId`. For information\n on setting up the Google Cloud Project, see\n [Create your Fleet Engine project](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/create-project).\n\n ### Java\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\n ### Kotlin\n\n val driverContext =\n DriverContext.builder(application)\n .setProviderId(providerId)\n .setVehicleId(vehicleId)\n .setAuthTokenFactory(authTokenFactory)\n .setNavigator(navigator)\n .setRoadSnappedLocationProvider(NavigationApi.getRoadSnappedLocationProvider(application))\n .build()\n\n3. Use the `DriverContext` object to initialize the `*DriverApi`.\n\n DeliveryDriverApi driverApi = DeliveryDriverApi.createInstance(driverContext);\n\n4. Obtain the `DeliveryVehicleReporter` from the API object.\n (`DeliveryVehicleReporter` extends `NavigationVehicleReporter`.)\n\n DeliveryVehicleReporter vehicleReporter = driverApi.getDeliveryVehicleReporter();\n\nNotes on SSL/TLS\n----------------\n\nInternally, the Driver SDK implementation uses\nSSL/TLS to communicate securely with the Fleet Engine service. Android API\nversions 23 or\nearlier may require a `SecurityProvider` patch to communicate with the\nserver. For more information about working with SSL in Android, see\n[Security GMS Provider](https://developer.android.com/training/articles/security-gms-provider).\nThe article also contains code samples for patching the security provider.\n\nWhat's next\n-----------\n\n[Get the vehicle ready](/maps/documentation/mobility/driver-sdk/scheduled/android/vehicle-ready)"]]