Track your first user

In this guide, we will setup the HyperTrack SDK in your Android app and start a Trip. A Trip is a journey that has a location stream, forming a polyline with distance. At the end of the guide, we will visualize the Trip on the dashboard.

If you're on iOS, read the iOS version of this guide.

Step 1: Install the SDK

In your app's build.gradle file, define the repositories and dependencies as shown. Once configured, run a gradle sync to import the SDK and its dependencies to your project.

Install SDK

repositories {
    maven { url "http://hypertrack-android-sdk.s3-website-us-west-2.amazonaws.com/" }
}

dependencies {
    compile("io.hypertrack:transmitter:1.5.13:release@aar") {
        transitive = true;
    }
}

Proguard Rules

If you are using Proguard in your project add the following lines to your proguard configuration file (proguard-rules.pro):

-keep class io.hypertrack.lib.** { *; }
-dontwarn io.hypertrack.lib.**

[info] Example app

If you are looking to build an app from scratch, you can use our example Android app built on the SDK.

Step 2: Configure the SDK

Once the SDK has been installed, we can use the SDK methods inside Android Studio. The first step is to configure your publishable key and initialise the SDK.

We will do this in the onCreate method of your Application class, so that it will be configured for the entire lifecycle of the app.

Configure SDK

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  ...

  HyperTrack.setPublishableApiKey("YOUR_PUBLISHABLE_KEY", getApplicationContext());
  HTTransmitterService.initHTTransmitter(getApplicationContext());
}

[warning] Location permissions

Make sure that your app is enabled for location before you can use the SDK methods (screenshot).

Step 3: Start the Trip

Now that the SDK has been initialised, we can start a Trip. The SDK has methods to start a Trip, and these can be hooked to a view or button in your application where tracking should start.

[info] Starting trips server-side

It is also possible to start a Trip from a server-side API, and trigger the SDK to send locations. This will prevent the need for user behavior to start tracking, and can be done from the backend. Read more about Android trips.

Start trip

HTTripParamsBuilder htTripParamsBuilder = new HTTripParamsBuilder();
HTTripParams htTripParams = htTripParamsBuilder.createHTTripParams();

HTTransmitterService transmitterService = HTTransmitterService.getInstance(getApplicationContext());
transmitterService.startTrip(htTripParams, new HTTripStatusCallback() {
  @Override
  public void onError(Exception error) {
    // Handle startTrip API error here
  }

  @Override
  public void onSuccess(HTTrip trip) {
    // Handle startTrip API success to server here
  }

  @Override
  public void onOfflineSuccess() {
    // Handle offline startTrip API success here (startTrip request has been
    // cached, starting the DriverSDK and it will be synced with server once
    // the device comes online)
  }
});

Step 4: View dashboard

Once the Trip has been started, you can view it on the dashboard.

Step 5: End the Trip

To end tracking, use the SDK methods to end trips. Hook these methods to a view or button where you want to end tracking.

HTTransmitterService transmitterService = HTTransmitterService.getInstance(getApplicationContext());
transmitterService.endTrip(new HTTripStatusCallback() {
  @Override
  public void onError(Exception error) {
    // Handle endTrip API error here
  }

  @Override
  public void onSuccess(HTTrip trip) {
    // Handle endTrip API success to server here
  }

  @Override
  public void onOfflineSuccess() {
    // Handle offline endTrip API success here (endTrip request has been
    // cached and it will be synced with server once the device comes online)
  }
});

[success] SDK integrated

We just configured the SDK in your app and started tracking the user on the dashboard. This was achieved with the Trip object. A Trip can have 0 or more Tasks, like a pickup, or an appointment. The next guide covers using Tasks in your workflow.

results matching ""

    No results matching ""