A client for Google's Fleet Engine.
This class allows the caller to enable
and disableLocationTracking()
disable location tracking. The frequency of updates can be controlled
with setLocationReportingInterval(long, TimeUnit)
.
This class is not thread-safe.
Nested Class Summary
interface | FleetEngine.AuthTokenFactory | Instances of this interface will be asked to provide an authorization token when various operations are performed. | |
class | FleetEngine.ErrorListener | The Fleet Engine client will use instances of this interface to inform the developer when important exceptions occur. | |
interface | FleetEngine.FleetEngineConfig | This interface is deprecated. legacy hook | |
interface | FleetEngine.StatusListener | Listener for status updates. | |
enum | FleetEngine.VehicleState | Indicates whether a vehicle is accepting new trips. |
Public Method Summary
static void |
clearInstance()
clearInstance stops location tracking, clears up internal state, and resets the FleetEngine
singleton to null.
|
static void |
createInstance(Application application, String providerId, String vehicleId, FleetEngine.AuthTokenFactory authTokenFactory, FleetEngine.ErrorListener errorListener)
Creates the
FleetEngine singleton, which can be used to access the Google Fleet Engine
service. |
static void |
createInstance(Application application, String providerId, String vehicleId, FleetEngine.AuthTokenFactory authTokenFactory, FleetEngine.StatusListener statusListener, FleetEngine.ErrorListener errorListener)
Creates the
FleetEngine singleton, which can be used to access the Google Fleet Engine
service. |
void |
disableLocationTracking()
Stops location tracking.
|
void |
enableLocationTracking()
Start uploading position reports to the Fleet Engine backend.
|
static FleetEngine |
getInstance()
Returns the FleetEngine singleton.
|
long |
getLocationReportingIntervalMs()
Returns the current location reporting interval, in milliseconds.
|
boolean |
isLocationTrackingEnabled()
Returns whether location tracking is enabled.
|
static void | |
void |
setLocationReportingInterval(long interval, TimeUnit intervalUnits)
Sets the minimum interval at which location reports will be delivered to the Fleet Engine
backend.
|
static void |
setNavigator(Navigator navigator)
|
void |
Inherited Method Summary
Public Methods
public static void clearInstance ()
clearInstance stops location tracking, clears up internal state, and resets the FleetEngine singleton to null.
public static void createInstance (Application application, String providerId, String vehicleId, FleetEngine.AuthTokenFactory authTokenFactory, FleetEngine.ErrorListener errorListener)
Creates the FleetEngine
singleton, which can be used to access the Google Fleet Engine
service. Internally, this method obtains a RoadSnappedLocationProvider
using getRoadSnappedLocationProvider(Application)
, so a Navigator
must be successfully
obtained before calling this method, otherwise it will result in an IllegalStateException
. Calling createInstance() twice will result in an IllegalStateException
.
Parameters
application | the current Application , must not be null |
---|---|
providerId | the ID of the provider |
vehicleId | the ID of the vehicle that will be connected to the Fleet Engine |
authTokenFactory | the factory that supplies Fleet
Engine authorization tokens |
errorListener | the listener that will be notified when
Fleet Engine client errors occur |
Throws
IllegalStateException | if the provider ID is not specified in AndroidManifest.xml
|
---|
public static void createInstance (Application application, String providerId, String vehicleId, FleetEngine.AuthTokenFactory authTokenFactory, FleetEngine.StatusListener statusListener, FleetEngine.ErrorListener errorListener)
Creates the FleetEngine
singleton, which can be used to access the Google Fleet Engine
service. Internally, this method obtains a RoadSnappedLocationProvider
using getRoadSnappedLocationProvider(Application)
, so a Navigator
must be successfully
obtained before calling this method, otherwise it will result in an IllegalStateException
. Calling createInstance() twice will result in an IllegalStateException
.
Parameters
application | the current Application , must not be null . |
---|---|
providerId | the ID of the provider. |
vehicleId | the ID of the vehicle that will be connected to the Fleet Engine |
authTokenFactory | the factory that supplies Fleet
Engine authorization tokens. |
statusListener | listener for status updates. |
errorListener | the listener that will be notified when
Fleet Engine client errors occur. |
Throws
IllegalStateException | if the provider ID is not specified in AndroidManifest.xml .
|
---|
public void disableLocationTracking ()
Stops location tracking. No attempt is made to stop a report that is already in progress, but no new position reports will be generated or transmitted.
Tracking can be resumed after stopping by calling enableLocationTracking()
again.
Throws
IllegalStateException | if location tracking was already stopped |
---|
public void enableLocationTracking ()
Start uploading position reports to the Fleet Engine backend. Reports are made periodically, by default every 5 seconds. Reports may be made less frequently if transient issues, such as loss of network connectivity, prevent report delivery.
Position reports are made in a background thread, this call returns immediately.
Location tracking may be disabled by calling disableLocationTracking()
.
Reporting interval can be changed with setLocationReportingInterval(long, TimeUnit)
.
Throws
IllegalStateException | if location tracking was already enabled |
---|
public static FleetEngine getInstance ()
Returns the FleetEngine singleton. createInstance() must be called prior to getInstance(), otherwise null will be returned.
public long getLocationReportingIntervalMs ()
Returns the current location reporting interval, in milliseconds.
public boolean isLocationTrackingEnabled ()
Returns whether location tracking is enabled.
public void setLocationReportingInterval (long interval, TimeUnit intervalUnits)
Sets the minimum interval at which location reports will be delivered to the Fleet Engine backend. The default reporting interval is 10 seconds. The minimum supported update interval is 5 seconds. More frequent updates may result in slower requests and errors.
Parameters
interval | |
---|---|
intervalUnits |
public void setVehicleState (FleetEngine.VehicleState state)
Sets the VehicleState. If location updates are enabled, the value will propagate at the next location update. If location updates are disabled, the update is fired immediately.
VehicleState update is made in a background thread, this call returns immediately.
Parameters
state |
---|
Throws
IllegalStateException | if VehicleState is set ONLINE when location tracking is not yet enabled. |
---|