Khởi chạy SDK trình điều khiển
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trước khi sử dụng Driver SDK, trước tiên, bạn phải khởi chạy Navigation SDK và Driver SDK theo các bước sau:
Lấy đối tượng Navigator
từ 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
}
},
)
Tạo một đối tượng DriverContext
, điền thông tin vào các trường bắt buộc. Để khởi tạo đối tượng DriverContext
, bạn phải nhập Mã dự án của Dự án trên Google Cloud làm providerId
. Để biết thông tin về cách thiết lập Dự án Google Cloud, hãy xem phần Tạo dự án 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()
Sử dụng đối tượng DriverContext
để khởi động *DriverApi
.
Java
RidesharingDriverApi ridesharingDriverApi = RidesharingDriverApi.createInstance(driverContext);
Kotlin
val ridesharingDriverApi = RidesharingDriverApi.createInstance(driverContext)
Lấy RidesharingVehicleReporter
từ đối tượng API.
(*VehicleReporter
kéo dài NavigationVehicleReporter
.)
Java
RidesharingVehicleReporter vehicleReporter = ridesharingDriverApi.getRidesharingVehicleReporter();
Kotlin
val vehicleReporter = ridesharingDriverApi.getRidesharingVehicleReporter()
Lưu ý về SSL/TLS
Về nội bộ, việc triển khai Driver SDK sử dụng SSL/TLS để giao tiếp an toàn với dịch vụ Fleet Engine. Android API phiên bản 23 trở xuống có thể yêu cầu bản vá SecurityProvider
để giao tiếp với máy chủ. Để biết thêm thông tin về cách sử dụng SSL trong Android, hãy xem Nhà cung cấp GMS bảo mật.
Bài viết này cũng chứa các mẫu mã để vá nhà cung cấp dịch vụ bảo mật.
Bước tiếp theo
Chuẩn bị xe
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\u003cp\u003eBefore utilizing the Driver SDK, ensure the Navigation SDK and Driver SDK are initialized by obtaining a \u003ccode\u003eNavigator\u003c/code\u003e object and creating a \u003ccode\u003eDriverContext\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eDriverContext\u003c/code\u003e requires your Google Cloud Project ID and other identifying information to establish communication with Fleet Engine.\u003c/p\u003e\n"],["\u003cp\u003eInitialize the specific Driver API, such as \u003ccode\u003eRidesharingDriverApi\u003c/code\u003e, using the created \u003ccode\u003eDriverContext\u003c/code\u003e for access to relevant functionalities.\u003c/p\u003e\n"],["\u003cp\u003eObtain the appropriate \u003ccode\u003eVehicleReporter\u003c/code\u003e from the initialized API to enable vehicle tracking and reporting within your application.\u003c/p\u003e\n"],["\u003cp\u003eThe Driver SDK utilizes SSL/TLS for secure communication and may require a \u003ccode\u003eSecurityProvider\u003c/code\u003e patch for older Android API versions.\u003c/p\u003e\n"]]],[],null,["Before 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 Java \n\n RidesharingDriverApi ridesharingDriverApi = RidesharingDriverApi.createInstance(driverContext);\n\n Kotlin \n\n val ridesharingDriverApi = RidesharingDriverApi.createInstance(driverContext)\n\n4. Obtain the `RidesharingVehicleReporter` from the API object.\n (`*VehicleReporter` extends `NavigationVehicleReporter`.)\n\n Java \n\n RidesharingVehicleReporter vehicleReporter = ridesharingDriverApi.getRidesharingVehicleReporter();\n\n Kotlin \n\n val vehicleReporter = ridesharingDriverApi.getRidesharingVehicleReporter()\n\nNotes on SSL/TLS\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[Get the vehicle ready](/maps/documentation/mobility/driver-sdk/on-demand/android/vehicle-ready)"]]