Android SDK Additional Features
Collision Detection
By default, collision detection is enabled in the SDK and is active when a drive is in progress.
Implement the onAccident
handler in your ZendriveBroadcastReceiver
to process callbacks from the collision.
Testing Collision Detection
After setting up the SDK in collision detection mode, you can test your integration using the triggerMockAccident
method. This emulates a fake collision and invokes the onAccident
handler in the ZendriveBroadcastReceiver
.
Zendrive.triggerMockAccident(this.getApplicationContext(),
ZendriveAccidentConfidence.HIGH,
new ZendriveOperationCallback() {
@Override
public void onCompletion(ZendriveOperationResult result) {
if (result.isSuccess()) { ... }
else { ... }
}
}
);
This requires the SDK to be set up and a trip to be in progress.
Manual Trip Tagging
Some applications, such as taxi-metering applications, already have knowledge of point-to-point trips made by the driver using the application, and may prefer to manually start and stop trips.
Zendrive.startDrive(context, <TRACKING_ID>, // A non empty <TRACKING_ID> must be specified
new ZendriveOperationCallback() {
@Override
public void onCompletion(ZendriveOperationResult result) {
if (result.isSuccess()) { ... }
else { ... }
}
}
);
Zendrive.stopManualDrive(context,
new ZendriveOperationCallback() {
@Override
public void onCompletion(ZendriveOperationResult result) {
if (result.isSuccess()) { ... }
else { ... }
}
}
);
Your application can then use the <TRACKING_ID>
argument to find Zendrive trips with this ID in Zendrive Analytics.
Using Manual Trip Tagging with Limited Permissions
If you use Zendrive SDK for manual trips only, you can detect and record trips with only While in use location permissions. You would not need background location permission.
This feature assumes that the request for location updates was started in the foreground, such as when starting a manual trip.
In case your application is killed while in the background, the trip may need to be resumed. You may have to send the user a notification asking them to click on it to resume the drive. Use the following flow:
The Zendrive SDK communicates a potential trip resume using the
onZendriveSettingsConfigChanged
callback.Your application calls the
getZendriveSettings()
API to get error information.A
LOCATION_UNAVAILABLE_WHILE_DRIVE_RESUME
error is sent.Your application shows the user a notification asking them to click on it.
The user clicks on the notification to launch the app in the foreground.
Once application is in foreground and all settings errors are fixed, the application calls
zendrive.setup
again.The drive resumes.
Vehicle Tagging
Zendrive SDK is capable of identifying a vehicle based on a paired Bluetooth ID generated from a Bluetooth stereo, enabling finer detail on whether the end-user is driving their own vehicle or is a passenger in a different vehicle.
To associate or dissociate a vehicle with the user account, use the following calls.
String vehicleId = "VEHICLE_IDENTIFIER"; // Unique identifier for the vehicle
String bluetoothAddress = "00:43:A8:23:10:F0"; // Hardware address of the vehicle's bluetooth
ZendriveVehicleInfo zendriveVehicleInfo = new ZendriveVehicleInfo(vehicleId, bluetoothAddress);
// Associate a vehicle
result = ZendriveVehicleTagging.associateVehicle(context, zendriveVehicleInfo);
// Dissociate a vehicle
result = ZendriveVehicleTagging.dissociateVehicle(context, vehicleId);
// Get list of associated vehicles
associatedVehicleInfoList = ZendriveVehicleTagging.getAssociatedVehicles(context);
Vehicle tagging aids vehicle-restricted insurance in case the user drives multiple vehicles, or is a passenger.
This feature is also used for tying usage metrics to a vehicle rather than a user. This is useful in case multiple family members drive the same vehicle, or in cases where a fleet owner needs metrics on specific vehicles.
The DriveInfo
class now has a tags
array. The getAssociatedVehicleIdForDrive
function fetches the vehicleId
tag from the tags
array.
public class DriveInfo implements Parcelable {
...
/**
* A list of ZendriveTagInfo objects for this drive.
*
* The list will be populated only in the AnalyzedDriveInfo.
*/
public ArrayList<ZendriveTagInfo> tags;
...
}
//Use ZendriveVehicleTagging.getAssociatedVehicleIdForDrive(DriveInfo driveInfo)
//to get the vehicleId from the AnalyzedDriveInfo object.
public class MyZendriveBroadcastReceiver extends ZendriveBroadcastReceiver {
...
@Override
public void onDriveAnalyzed(Context context, AnalyzedDriveInfo analyzedDriveInfo) {
...
// Will be null if the device did not connect to the bluetooth of any associated vehicles during the drive
String vehicleId = ZendriveVehicleTagging.getAssociatedVehicleIdForDrive(analyzedDriveInfo);
...
}
...
}
Driving Sessions
Some applications want to track multiple point-to-point trips together as a single entity. For example, a car rental app may want to track all trips made by a user between a rental car pickup and drop-off as a single entity. You can do this using sessions in Zendrive SDK. Use the following calls to use sessions.
Zendrive.startSession(context, <Session ID>);
// A non empty <SESSION ID> must be specified
Zendrive.stopSession(context);
Zendrive SDK tags all trips within a session with a single session ID. You can then use the session ID to look up Zendrive trips belonging to this session using Zendrive Analytics.
Controlling Automatic Drive Detection
Zendrive SDK works in the background and automatically detects trips and tracks driving behavior. If needed, an application can change this behavior. For example, a ride-sharing application may want to automatically track all trips only when the user is on-duty, not collect any data for off-duty trips.
The application can specify the required behavior during Zendrive SDK setup.
//ZendriveDriveDetectionMode.AUTO_OFF disables automatic drive detection in the SDK.
ZendriveConfiguration zendriveConfiguration = new ZendriveConfiguration(
zendriveApplicationKey, <DRIVER_ID>, ZendriveDriveDetectionMode.AUTO_OFF);
Zendrive.setup(
this.getApplicationContext(),
zendriveConfiguration,
MyZendriveBroadcastReceiver.class, // can be null.
MyZendriveNotificationProvider.class, // must be non-null.
new ZendriveOperationCallback() {
@Override
public void onCompletion(ZendriveOperationResult result) {
if (result.isSuccess()) { ... }
else { ... }
}
}
);
The application can also temporarily enable Zendrive's automatic drive-detection. This can be done by setting the ZendriveDriveDetectionMode
.
// Turn on automatic drive detection in the SDK.
Zendrive.setZendriveDriveDetectionMode(context, ZendriveDriveDetectionMode.AUTO_ON,
new ZendriveOperationCallback() {
@Override
public void onCompletion(ZendriveOperationResult result) {
if (result.isSuccess()) { ... }
else { ... }
}
}
);
...
// Turn off automatic drive detection in the SDK.
Zendrive.setZendriveDriveDetectionMode(context, ZendriveDriveDetectionMode.AUTO_OFF,
new ZendriveOperationCallback() {
@Override
public void onCompletion(ZendriveOperationResult result) {
if (result.isSuccess()) { ... }
else { ... }
}
}
);
Was this helpful?