Installing the SDK

This guide will help you setup the Android SDK in your application and configure it to be controlled via REST APIs. The SDK is built to collect locations and related data in a battery efficient way, and has methods to start and stop data collection, and interact with the HyperTrack APIs.

If you're looking for an example integration, use the example-android application.

[warning] Requirements

The SDK is compatible with Android 4.1 (API level 16) and above. Also, the SDK can only be used in devices that support GPS. Only A-GPS devices are not supported.

Install the dependency

In your app's build.gradle file, define the repositories and dependencies as shown.

[info] build.gradle files

Your project will have two gradle files: one for the app module, and one for the project. Edit the app module file to install the SDK.

Once configured, run a gradle sync to import the SDK and its dependencies to your project.

[info] Other dependencies

The SDK installs the following dependencies

  • Google play services, v9.6.1
  • Gson library, v2.4
  • Paho client library for mqtt, v1.1.1-SNAPSHOT
  • Volley client, v1.0.0

If any of these are already dependencies for your app, verify that the minimum version requirements for the SDK are met.

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;
    }
}

[warning] Manifest mergers

Like all Android projects, the SDK has its own AndroidManifest.xml file. When you integrate the SDK with your application, the manifest files of your application and the SDK are merged. It is possible that there are some merge conflicts which cause issues.

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    tools:replace="activity"> // Don't do this!
    ...

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.**

Configure the API key

To configure the SDK, set the publishable key. Also, initialize the SDK in the onCreate method of your Application class, so that it will be configured for the entire lifecycle of your app.

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

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

[info] Location permissions

  • The SDK requires the ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions. These are already included in the SDK manifest.
  • In case your app is for Marshmallow and above (API level 23+), you will need to implement run-time permissions for location. Read more at Android docs.
  • For high quality location collection, the SDK needs the location to be set at high accuracy. See settings screenshot. Read more at Android docs to do it programmatically.

Connect the SDK

Initialise the SDK connection to the server by passing the driver id to the connectDriver method. This should be done in the onResume method of your app's Launcher or Main activities.

[info] Driver entity

If you don't have a driver id, refer to the creating a Driver server-side API.

@Override
protected void onResume() {
  super.onResume();

  // Initiate DriverSDK connection
  HTTransmitterService.connectDriver(getApplicationContext(), driverID,
    new TransmitterErrorCallback() {
      @Override
      public void onError(final int errorCode, final String errorMessage) {
        // Handle connectDriver Error here
        // Refer to TransmitterError.java file for Error codes & messages
        // Note: This callback might be called on a worker thread, so handle
        // the errors accordingly. To run commands on MainThread refer to
        // runOnUiThread API in Android documentation
      }
  });
}

Once the SDK has been connected, it is ready to be controlled by the server-side APIs.

results matching ""

    No results matching ""