Fleet Connectivity
The Fleet Connectivity features allow applications that use SDK for Android to receive job dispatches from a fleet dispatcher. Each job dispatch contains custom information such as a geocoordinate to a destination that can be used by your application for navigation or other purposes.
Your application, which is known as an asset in a fleet connectivity context, can also use this feature to indicate its job status to the dispatcher. These job statuses include whether it is available to receive a job, whether the job was accepted, and whether the job is finished.
FleetConnectivityService
This singleton class holds information such as this fleet asset ID, the fleet dispatcher to connect to, the running job, and job event polling interval.
FleetConnectivityEvent and FleetConnectivityService.Listener
You can set a FleetConnectivityService.Listener
to the service to listen for dispatcher events. Dispatcher events are highly customizable with the only mandatory information being a Job ID. Otherwise, you can define any type of information in its content
payload such as a set of geocoordinates, a Place ID, or an address string.
Listener
: -
onMessageReceived(FleetConnectivityMessage)
-
onEventAcknowledged(FleetConnectivityEvent, FleetConnectivityError)
Using the Fleet Connectivity Feature
- Start the fleet connectivity service and begin listening for fleet connectivity events.
FleetConnectivityService service = FleetConnectivityService.getInstance(); service.setDispatcherId("Driver-321"); service.setAssetId("Truck-987"); if (service.start()) { // service has started } else { // service has failed to start }
- Implement
Listener
. Once a message is received, check if it is a dispatch job.public void onMessageReceived(FleetConnectivityMessage message) { if (message.getMessage() != null) { // Display the optional message content } if (message instanceof FleetConnectivityJobMessage) { // This message represents a job FleetConnectivityJobMessage newDestinationMessage = (FleetConnectivityJobMessage) message; // Get job ID from newDestinationMessage.getJobId() // Get location (in your preferred format) from // newDestinationMessage.getMessage() // Get threshold from newDestinationMessage.getEtaThreshold() // (this threshold controls when ETA updates are sent back to dispatcher) } else if (message instanceof FleetConnectivityCustomMessage) { // This message does not represent a job FleetConnectivityCustomMessage customMessage = (FleetConnectivityCustomMessage) message; // Get job ID from customMessage.getJobId() // Get message from customMessage.getContent() } }
- Send an event to the dispatcher that the job has been accepted.
Alternatively, you can also reject the job by sending a rejection event.FleetConnectivityJobStartedEvent event = new FleetConnectivityJobStartedEvent(); // populate event.setJobId(String) // populate event.setEtaThreshold(long) if (FleetConnectivityService.getInstance().sendEvent(event)) { // job is running // for example, your application can begin navigating to the job destination } else { // job has failed to start }
FleetConnectivityJobRejectedEvent event = new FleetConnectivityJobRejectedEvent(); // populate event.setJobId(String) if (!FleetConnectivityService.getInstance().sendEvent(event)) { // failed to reject job }
- While a job is in the accepted state, you can tell the dispatcher that the job is canceled.
FleetConnectivityJobCancelledEvent event = new FleetConnectivityJobCancelledEvent(); if (!FleetConnectivityService.getInstance().sendEvent(event)) { // failed to cancel job }
- Upon job completion, notify the server that the job is finished. For example, you can choose to send this event when your application has successfully finished the navigation session.
FleetConnectivityJobFinishedEvent event = new FleetConnectivityJobFinishedEvent(); if (!FleetConnectivityService.getInstance().sendEvent(event)) { // failed to mark job as finished }
- In the previous steps after sending each event your application receives an acknowledgment from the dispatching server through the
onEventAcknowledged(FleetConnectivityEvent, FleetConnectivityError)
callback.public void onEventAcknowledged(FleetConnectivityEvent event, FleetConnectivityError error) { if (event instanceof FleetConnectivityJobStartedEvent) { // the job start event is acknowledged } else if (event instanceof FleetConnectivityJobRejectedEvent) { // the job rejection event is acknowledged } else if (event instanceof FleetConnectivityJobFinishedEvent) { // the job completion event is acknowledged } else if (event instanceof FleetConnectivityJobCancelledEvent) { // the job cancellation event is acknowledged } else if (event instanceof FleetConnectivityCustomEvent) { // the custom event is acknowledged } }
- Stop the service by calling
FleetConnectivityService.getInstance().stop()
.