Skip to content
Get HyperTrack data directly on your Android app to build views
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea Initial commit Jul 16, 2019
app Version updated to 0.3.1 (#3) Aug 12, 2019
gradle/wrapper Initial commit Jul 16, 2019
.gitignore Initial commit Jul 16, 2019
README.md Version updated to 0.3.1 (#3) Aug 12, 2019
build.gradle Initial commit Jul 16, 2019
gradle.properties Initial commit Jul 16, 2019
gradlew Initial commit Jul 16, 2019
gradlew.bat Initial commit Jul 16, 2019
settings.gradle Initial commit Jul 16, 2019

README.md

Android Views SDK

The Android Views SDK is used for getting live location and movement data for devices and trips directly to your Android app. This module subscribes to HyperTrack's GraphQL server end points to get data streams and then renders it in useful callbacks for app developers to build beautiful tracking experiences. This helps developers creating live location views go serverless. Their app users can directly get data securely and privately from the HyperTrack servers.

Integrate the Views SDK

Step 1. Add Views SDK

Add following lines to your applications build.gradle:

// Import the SDK within your repositories block
repositories {
    maven {
        name 'hypertrack'
        url 'http://m2.hypertrack.com'
    }
    ...
}

//Add HyperTrack Views SDK as a dependency
dependencies {
    implementation 'com.hypertrack:hypertrack-views:0.3.1'
    ...
}

Step 2. Instantiate

Pass Context reference to get SDK instance.

   HyperTrackViews hypertrackView = HyperTrackViews.getInstance(this, PUBLISHABLE_KEY);

Step 3. Get state

Get current state of tracked device

   hypertrackView.getDeviceMovementStatus(deviceId,
                                  new Consumer<MovementStatus>() {
                                      @Override
                                      public void accept(MovementStatus movementStatus) {
                                          Log.d(TAG, "Got movement status data " + movementStatus);
                                      }
                                  });

In callback, that you pass as a second argument, you'll receive MovementStatus object that encapsulates various data describing device state. Check out docs for data that is available.

Step 4. Subscribe to updates

You can receive device state changes updates

   hypertrackView.subscribeToDeviceUpdates(deviceId,
   new DeviceUpdatesHandler() {
           @Override
           public void onLocationUpdateReceived(@NonNull Location location) {
               Log.d(TAG, "onLocationUpdateReceived: " + location);
           }

           @Override
           public void onBatteryStateUpdateReceived(@BatteryState int i) {
               Log.d(TAG, "onBatteryStateUpdateReceived: " + i);
           }

           @Override
           public void onStatusUpdateReceived(@NonNull StatusUpdate statusUpdate) {
               Log.d(TAG, "onStatusUpdateReceived: " + statusUpdate);
           }

           @Override
           public void onTripUpdateReceived(@NonNull Trip trip) {
               Log.d(TAG, "onTripUpdateReceived: " + trip);

           }

           @Override
           public void onError(Exception e, String deviceId) {
               Log.w(TAG, "onError: ", e);

           }

           @Override
           public void onCompleted(String deviceId) {
               Log.d(TAG, "onCompleted: " + deviceId);

           }
       }
   );

Likewise in case of one-time status query you'll receive updates object in a listener, that you pass into this method. Check out documentation for available update object properties. Make sure you've stop updates, once you're done since you can end up with leaked websocket otherwise.

   hypertrackView.stopAllUpdates();

You are all set

Frequently Asked Questions

Supported versions

Currently we do support all of the Android versions starting from API 19 (Android 4.4 Kit Kat)

Get device id

Device id is a way to reference particular device, that is tracked by HyperTrack SDK. Generally, it's your application logic which devices should be displayed and how to filter/prioritize/select the one you need to track. If you have doubts regarding how to integrate HyperTrack SDK - look into corresponding quickstart section. Once integration is done, device id can be obtained via HyperTrack.getDevcieid() call on initialized SDK.

Not Only Views in Views

Although view is associated with something, that should be visual, here it means view on data, that you retrieve from HyperTrack SDK. Tricky part is that application success nowadays is highly dependends on quality of user experience, that is hardly achievable without fine-grained tuning of UI elements. So using real-time data pushed to your device, you can build exactly the same views you really want. Anyway, ready to use UI elements will be added to upcoming library releases.

Track multiple devices

You can subscribe to more than one device by executing subscribeToDeviceUpdates multiple times with different device ids. Subscription updates consumer can be the same (e.g. map fragment), since each update has device id field for identification.

Trips Tracking

Each trip has a device id, for which it was created, pass that id to subscribeToDeviceUpdates and you'll receive all the trip recalculations and delays into onTripUpdateReceived callback.

Battery State Constants

Using enums in Android is discouraged, so we're using numerical values to represent BatteryState. Check out reference for exact values meaning.

You can’t perform that action at this time.