Android SDK reference

Methods

[info] SDK Javadoc

For a complete reference for SDK methods, refer to the SDK Javadoc.

Driver status methods

The SDK provides methods to the get the current status. Use the instance of the HTTransmitterService class to call these methods.

HTTransmitterService transmitterService =  HTTransmitterService.getInstance(this);
boolean isDriverActive = transmitterService.isDriverLive();
if (isDriverActive) {
    String activeDriverID = transmitterService.getDriverID();
}
Method Returns Description
isDriverLive boolean Returns true if the SDK is active for a driver, false otherwise.
getDriverID String Returns id of the driver locally saved in the SDK. Returns null if no driver was set.
isDriverConnected boolean Returns true if the SDK is connected to the server, false otherwise.

Intents

The SDK provides broadcasts which can be used in your app to determine changes in the current location or status. These intents are defined in TransmitterConstants.

Intent name Description
HT_DRIVER_CURRENT_LOCATION_INTENT Get the current location when the SDK is active
HT_ON_LOCATION_SERVICE_STARTED_INTENT Get notified when the location service has started
HT_ON_DRIVER_NOT_ACTIVE_INTENT Get notified when the location service has stopped

Current location intent

@Override
protected void onResume() {
  super.onResume();
  IntentFilter filter = new IntentFilter(TransmitterConstants.HT_DRIVER_CURRENT_LOCATION_INTENT);
  LocalBroadcastManager.getInstance(this).registerReceiver(driverCurrentLocationReceiver, filter);
}

BroadcastReceiver driverCurrentLocationReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent != null && intent.getExtras() != null) {
      // Get Driver's current location from Intent Extras
      Bundle bundle = intent.getExtras();
      Location location = bundle.getParcelable(TransmitterConstants.HT_DRIVER_CURRENT_LOCATION_KEY);

      // Handle Driver Location update received
      updateDriverLocation(location);
    }
  }
};

@Override
protected void onPause() {
  super.onPause();
  LocalBroadcastManager.getInstance(this).unregisterReceiver(driverCurrentLocationReceiver);
}

Service started intent

@Override
protected void onResume() {
  super.onResume();
  IntentFilter filter = new IntentFilter();
  filter.addAction(TransmitterConstants.HT_ON_LOCATION_SERVICE_STARTED_INTENT);
  LocalBroadcastManager.getInstance(this).registerReceiver(locationServiceStartedReceiver, filter);
}

BroadcastReceiver locationServiceStartedReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    // Handle driver is active intent

    // Get DriverID for whom the Service was started
    if (intent != null && intent.hasExtra(TransmitterConstants.HT_DRIVER_ID_KEY)) {
      String driverID = intent.getStringExtra(TransmitterConstants.HT_DRIVER_ID_KEY);
    }
  }
};

@Override
protected void onPause() {
  super.onPause();
  LocalBroadcastManager.getInstance(this).unregisterReceiver(locationServiceStartedReceiver);
}

Service stopped intent

@Override
protected void onResume() {
  super.onResume();
  IntentFilter filter = new IntentFilter();
  filter.addAction(TransmitterConstants.HT_ON_DRIVER_NOT_ACTIVE_INTENT);
  LocalBroadcastManager.getInstance(this).registerReceiver(driverNotActiveReceiver, filter);
}

BroadcastReceiver driverNotActiveReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    // Handle driver not active intent

    // Get DriverID for whom the Service was stopped
    if (intent != null && intent.hasExtra(TransmitterConstants.HT_DRIVER_ID_KEY)) {
      String driverID = intent.getStringExtra(TransmitterConstants.HT_DRIVER_ID_KEY);
    }
  }
};

@Override
protected void onPause() {
  super.onPause();
  LocalBroadcastManager.getInstance(this).registerReceiver(driverNotActiveReceiver, filter);
}

Was this helpful? Yes, thanks! Not really

results matching ""

    No results matching ""