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/FCM Dependency

When using Actions for a user, the SDK provides a better user experience if GCM/FCM has been integrated in the app and the device is online. Refer to our GCM/FCM integration guide for more details.

/**
  * Construct a place object for Action's expected place
  *
  * @NOTE: Either the coordinates for the Action's location
  * or it's address can be used to construct the expected place
  */
Place expectedPlace = new Place().setLocation(latitude, longitude)
                    .setAddress(address)
                    .setName(name);

/**
  * Create ActionParams object specifying the Visit Action parameters including 
  * ExpectedPlace, ExpectedAt time and Action's Lookup_id.
  */
ActionParams params = new ActionParamsBuilder().setExpectedPlace(expectedPlace)
        .setType(Action.ACTION_TYPE_VISIT)
        .setExpectedAt(expectedAtTimestamp)
        .setLookupId(<ACTION_LOOKUP_ID_HERE>)
        .build();

 /**
  * Call createAndAssignAction to assign Visit action to the current user
  * configured in the SDK using the ActionParams created above.
  */
HyperTrack.createAndAssignAction(actionParams, new HyperTrackCallback() {
    @Override
    public void onSuccess(@NonNull SuccessResponse response) {
        // Handle createAndAssignAction success 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();

Was this helpful? Yes, thanks! Not really

results matching ""

    No results matching ""