Using actions in Android SDK

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 use actions via the SDK.

Step 1: Start the SDK

To start tracking the user, use the startTracking method.

HyperTrack.startTracking();

Step 2: Assign actions to a user

Create and assign an Action object with the User Id. Refer to the Action model for more options.

[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 actionParams = 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();
      ...
  }
});

Step 3: View dashboard

Once you have assigned an action, run your app on a device. You would be able to view the action being performed on the ACTIONS tab on Dashboard.

Step 4: Fetch action details

In order to access action details from HyperTrack server in the app, use the getAction method for a given action id.

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();
      ...
  }
});

Step 5: Complete an action

Use the completeAction method to mark an action as completed.

HyperTrack.completeAction(actionId);

Step 6: Stop the SDK

To stop tracking the user, use the stopTracking method.

HyperTrack.stopTracking();

Sample References

Check out our open-sourced live location sharing and at-home service visit repositories for detailed reference.

Was this helpful? Yes, thanks! Not really

results matching ""

    No results matching ""