Obtaining a domain object
Vehicle SDK APIs are used by obtaining a domain object from the Vehicle entry point and then calling one of four types of APIs (Get, Set, Callback, Capability) on that object. See Introduction for the domain structure. For permissions, see Permission. For error handling, see Error code.
Create a Vehicle instance and connect to the vehicle service with initialize(), then obtain a domain object via a getXxx() method such as getDoor() or getDisplay(). Call Get, Set, Callback, and Capability APIs on the domain object, and release resources with release() when finished.
Because vehicle communication uses IPC, get, set, and capability results are not returned synchronously; they are delivered via asynchronous onComplete and onFailed callbacks. Do not call release() before those callbacks complete.
- Kotlin
- Java
// Create and initialize the Vehicle instance
val vehicle = Vehicle(context)
vehicle.initialize()
// Obtain a domain object via getXxx()
val door = vehicle.getDoor()
// Call Get / Set / Callback / Capability APIs on the door object
// ...
// Release resources when finished
vehicle.release()
// Create and initialize the Vehicle instance
Vehicle vehicle = new Vehicle(context);
vehicle.initialize();
// Obtain a domain object via getXxx()
Door door = vehicle.getDoor();
// Call Get / Set / Callback / Capability APIs on the door object
// ...
// Release resources when finished
vehicle.release();
The four API types
| Type | What it does | Result delivery | Doc |
|---|---|---|---|
| Capability | Check feature support and allowed ranges | onComplete(config, areaMap) / onFailed | Capability |
| Get | Read the current value | onComplete(value) / onFailed | Get |
| Set | Write a value | onFailed (on failure) | Set |
| Callback | Subscribe to state changes | listener onXxxUpdated / onFailed | Callback |
The API type examples assume the Vehicle instance (vehicle) has already been initialized.