Using Actions

An Action represents a pickup, delivery, visit or any other transaction event being performed by the User. In this guide, we will cover how to complete actions on the SDK.

Start the SDK

To start tracking the user, use the startTracking method.

HyperTrack.startTracking();

Assigning Actions to a User

Create and assign an Action object with the user id to start. You can refer to the Action model for more options. Action ends when it is marked complete using the completeAction API.

[info] GCM Dependency

When using Actions for a user, the SDK provides a better user experience if GCM has been integrated in the app and the device is online.

// Construct a place object for Action's expected place
Place expectedPlace = new Place().setLocation(latitude, longitude)
                    .setAddress(address)
                    .setName(name);

// Construct action params object
ActionParams params = new ActionParamsBuilder().setExpectedPlace(expectedPlace)
        .setType(Action.ACTION_TYPE_VISIT)
        .setExpectedAt(expectedAtTimestamp)
        .setLookupId("ACTION_LOOKUP_ID")
        .build();

HyperTrack.createAndAssignAction(actionParams, new HyperTrackCallback() {
    @Override
    public void onSuccess(@NonNull SuccessResponse response) {
        // Handle createAndAssignAction response here
      Action action = (Action) response.getResponseObject();
      ...
  }

  @Override
  public void onError(@NonNull ErrorResponse errorResponse) {
      // Handle createAndAssignAction error here
      Toast.makeText(this, errorResponse.getErrorMessage(), Toast.LENGTH_SHORT).show();
      ...
  }
});

Fetch Action details

Call getAction API to fetch action details for a given action id from HyperTrack Server.

HyperTrack.getAction(actionId, new HyperTrackCallback() {
    @Override
  public void onSuccess(@NonNull SuccessResponse response) {
      // Handle getAction response here
      Action actionResponse = (Action) response.getResponseObject();
      ...
  }

  @Override
  public void onError(@NonNull ErrorResponse errorResponse) {
      // Handle getAction error here
      Toast.makeText(this, errorResponse.getErrorMessage(), Toast.LENGTH_SHORT).show();
      ...
  }
});

Completing an Action

Call completeAction API to mark an action completed.

HyperTrack.completeAction(actionId);

Stop the SDK

To stop tracking the user, use the stopTracking method.

HyperTrack.stopTracking();

results matching ""

    No results matching ""