Android SDK Setup

To use HyperTrack SDK in your Android app, we first need to plug in the SDK into your app.

[info] Step-By-Step Onboarding

Setting up HyperTrack Android SDK in your app?

We recommend you try our new interactive step-by-step onboarding

Android Onboarding

 

[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. Devices utilizing only A-GPS are not supported.

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.

In case you're facing Gradle dependency conflict errors, refer here for detailed info.

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

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

dependencies {
    compile("com.hypertrack:android:0.2.6:release@aar") {
        transitive = true;
    }
}

[warning] Proguard rules

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

  • -keep class com.hypertrack.lib.** { *; }
  • -dontwarn com.hypertrack.lib.**

Step 2: Configure the SDK

Now that the SDK has been installed, you can use the SDK methods inside Android Studio. Configure your publishable key and initialise the SDK in the onCreate method of your Application class.

HyperTrack.initialize(this.getApplicationContext(), “YOUR_PUBLISHABLE_KEY”);

Step 3: Configure GCM/FCM key

GCM/FCM integration with HyperTrack SDKs enables realtimeness in tracking experiences across platforms.

For this, configure your GCM or FCM's Server key in the HyperTrack dashboard. GCM/FCM allows the SDK to be controlled by the server for better battery optimization and also adds robustness in recovering from crashes.

FCM Integration

To enable FCM integration, you need to change the base class for your implementation of FirebaseMessagingService to HyperTrackFirebaseMessagingService.

You can refer to Enable GCM/FCM guide for detailed steps or Test your GCM/FCM Integration section for testing your integration.

[info] Fresh FCM Integration

Add a new Service which extends HyperTrackFirebaseMessagingService to your application's manifest file with the tag as highlighted in the code snippet.

// Extend HyperTrackFirebaseMessagingService instead of FirebaseMessagingService
// No need to implement/override any method for HyperTrack SDK's FCM integration
// In case onMessageReceived method is overridden, super.onMessageReceived() method should be called.
public class AppFCMListenerService extends HyperTrackFirebaseMessagingService {
    ...
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        ...
    }
}
<!-- For fresh FCM integration, register the new file in your app's `AndroidManifest.xml` file -->
<service android:name=".AppFCMListenerService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

GCM Integration

To enable GCM integration, you need to change the base class for your implementation of GcmListenerService to HyperTrackGcmListenerService.

You can refer to Enable GCM/FCM guide for detailed steps or Test your GCM/FCM Integration section for testing your integration.

[info] Fresh GCM Integration

Add a new Service which extends HyperTrackGcmListenerService to your application's manifest file with the tag as highlighted in the code snippet.

// Extend HyperTrackGcmListenerService instead of GcmListenerService
// No need to implement/override any method for HyperTrack SDK's GCM integration
// In case onMessageReceived method is overridden, super.onMessageReceived() method should be called.
public class AppGCMListenerService extends HyperTrackGcmListenerService {
    ...
    @Override
    public void onMessageReceived(String from, Bundle data) {
        super.onMessageReceived(from, data);
        ...
    }
}
<!-- For fresh GCM integration, register the new file in your app's `AndroidManifest.xml` file -->
<service android:name=".AppGCMListenerService">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    </intent-filter>
</service>

Step 4: Enable location permissions

  • The SDK requires the ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions. These are already included in the SDK manifest so need not be explicitly added.

  • In case your app is for Marshmallow and above (API level 23+), Call requestPermissions() API to request for run-time location permissions.

  • For high quality location collection, the SDK needs location services enabled at high accuracy. Call requestLocationServices() API to request for user to enable Location Services in high-accuracy, if not enabled already.

Refer here for a sample implementation for requesting Location Permissions & Services.

// To request Location Permissions
HyperTrack.requestPermissions(this);

// To enable Location Services
HyperTrack.requestLocationServices(this, null);

[success] Setup SDK Completed

Now that we have the SDK plugged-in in your app, lets do a basic integration.

Was this helpful? Yes, thanks! Not really

results matching ""

    No results matching ""