DriveMotionClient
DriveMotion supports starting and stopping driving through method calls instead of automatic detection in MANUAL
mode. To use this feature, developers must obtain DriveMotionClient after initializing DriveMotion.
Get DriveMotionClient
1 2 3 4 5 |
|
1 2 3 4 5 |
|
Use DriveMotionClient
DriveMotionClient provides the entrance to start driving and stop driving manually, but DriveDetectionMode must be set to MANUAL
, otherwise DriveMotionException will be generated.
Start Drive
The startDrive
method will notify DriveMotion to start new trip. This is an asynchronous operation. When DriveMotion completes all necessary trip initialization, and then it will send a DriveStartEvent to the application via broadcast(by trigger onDriveStart
callback). Then the application can get the session id, trip id, start time and start location information with the SDK.
The necessary initialization includes obtaining current device status and location info. If initialization meets any error, and DriveMotionException is thrown. Please check the exception message and perform subsequent operations.
Start Drive in synchronous [Deprecated, using asynchronous instead]
1 2 3 4 5 |
|
1 2 3 4 5 |
|
Start Drive in asynchronous
1 2 3 4 5 6 7 8 9 10 11 12 |
|
1 2 3 4 5 6 7 8 9 10 |
|
Note
If multiple consecutive startDrive()
/startDriveRequest()
calls are made, all subsequent calls to startDrive requests will be ignored as the presence of currentTrip, and the entire trip will be treated as one consecutive trip.
Note
If the SDK could not obtain the valid location when startDrive()
/startDriveRequest()
, the thrown exception is described as invalid location
.
Some common status are:
- The device location service is not enabled.
- The device has not been able to obtain location since restarted.
- The current location has no GPS signal coverage.
There are several possible recovery methods for this situation:
- Check whether the device location service is started normally from Settings.
- Retry to
startDrive
with a delay. - If could not back to normal, try to re-initialize the SDK with a default GPS info. See
SDKOptions
section for details.
Stop Drive
The stopDrive
method will notify DriveMotion to end current trip. This is an asynchronous operation. When DriveMotion completes end, it will send two event to application via broadcast:
DriveEndEvent(by trigger onDriveEnd
callback). Then the application can get the session id, trip id, end time, end location and trip valid status information from the driveEndEvent.
Note
If the trip distance is too short or been detected as invalid trip, it will be hidden from any API calls when trip finished. The value driveEndEvent.isValidTrip
will indicate the specific status of the finished trip.
DriveAnalyzedEvent(by trigger onDriveAnalyzed
callback). Application can get the final trip information and score information from the driveAnalyzedEvent.
Stop Drive in synchronous [Deprecated, using asynchronous instead]
1 2 3 4 5 |
|
1 2 3 4 5 |
|
Stop Drive in asynchronous
1 2 3 4 5 6 7 8 9 10 11 12 |
|
1 2 3 4 5 6 7 8 9 10 |
|