Android SDK reference

Basic Integration

You will find all the methods related to basic integration of SDK here.

User

All methods that are related to User entities will find here.

Action

All methods that are related to Action entities will find here.

Notification

Methods to customize the Android Service Notification which persists on the lock screen and in the notifications view while the SDK is actively transmitting locations will find here.

HyperTrack Event Callback

HyperTrack SDK sends periodic events according to user's location behaviour, in order to capture these events developer can use a HyperTrack.setCallback method.

HyperTrack.setCallback(new HyperTrackEventCallback() {
    @Override
    public void onEvent ( @NonNull final HyperTrackEvent event){
        switch (event.getEventType()) {
            case HyperTrackEvent.EventType.STOP_ENDED_EVENT:
                //Write your logic here
                break;
            case HyperTrackEvent.EventType.TRACKING_STOPPED_EVENT:
                //Write your logic here
                break;
            case HyperTrackEvent.EventType.ACTION_ASSIGNED_EVENT:
                //Write your logic here
                break;
            case HyperTrackEvent.EventType.ACTION_COMPLETED_EVENT:
                //Write your logic here
                break;
            case HyperTrackEvent.EventType.STOP_STARTED_EVENT:
                //Write your logic here
                break;
                ....
                ....
        }
    }
}
Event Type
STOP_STARTED_EVENT
STOP_ENDED_EVENT
TRACKING_STARTED_EVENT
TRACKING_STOPPED_EVENT
ACTION_ASSIGNED_EVENT
ACTION_COMPLETED_EVENT
LOCATION_CHANGED_EVENT

Check Location Permission

HyperTrack.checkLocationPermission API allows to check whether user has granted location permission for the app or not. Only requirement for this API is the SDK to be initialized and Location Settings to be enabled.

Returns true if the location permission has been granted or not required, false otherwise.

HyperTrack.initialize(this.getApplicationContext(), "<YOUR_PUBLISHABLE_KEY>");
HyperTrack.checkLocationPermission(context);

Request Permission

HyperTrack.requestPermissions API allows to request location permission to power HyperTrack SDK. Only requirement for this API is the SDK to be initialized and Location Settings to be enabled.

HyperTrack.initialize(this.getApplicationContext(), "<YOUR_PUBLISHABLE_KEY>");
HyperTrack.requestPermissions(activityInstance);

Check Location Service

HyperTrack.checkLocationServices API allows to check whether user has enable location services for the app or not. Only requirement for this API is the SDK to be initialized and Location Settings to be enabled.

Returns true if the location services are enabled in HIGH_ACCURACY mode, false otherwise.

HyperTrack.initialize(this.getApplicationContext(), "<YOUR_PUBLISHABLE_KEY>");
HyperTrack.checkLocationServices(context);

Request Permission

HyperTrack.requestLocationServices API allows to request user to enabel location services to power HyperTrack SDK. Only requirement for this API is the SDK to be initialized and Location Settings to be enabled.

[warning] Activity or Context ?

Pass instance of the AppCompatActivity where location services needs to be enabled.

HyperTrack.initialize(this.getApplicationContext(), "<YOUR_PUBLISHABLE_KEY>");
HyperTrack.requestLocationServices(activityInstance,new HyperTrackCallback() {
    @Override
    public void onSuccess(@NonNull SuccessResponse response) {

    }

    @Override
    public void onError(@NonNull ErrorResponse errorResponse) {
        Toast.makeText(Home.this, "Please enable location", Toast.LENGTH_SHORT).show();
    }
});

Note: onSuccess method will invoke if location was enabled or location dialog shows up.

Get Current Location

HyperTrack.getCurrentLocation API allows you to fetch device's current location. Only requirement for this API is the SDK to be initialized and Location Settings to be enabled.

HyperTrack.initialize(this.getApplicationContext(), "<YOUR_PUBLISHABLE_KEY>");
HyperTrack.getCurrentLocation(new HyperTrackCallback() {
    @Override
    public void onSuccess(@NonNull SuccessResponse response) {
        // Handle getCurrentLocation API success here      
        Location location = (Location) response.getResponseObject();   
        ...
    }

    @Override
    public void onError(@NonNull ErrorResponse errorResponse) {
        // Handle getCurrentLocation API error here
    }
});

Enable GNSS Measurement

HyperTrack.enableGNSSMeasurement used to enable or disable GNSS Measurement including NAVSTAR (GPS), GLONASS, GALILEO, BEIDOU etc.

[warning] Default

By default, SDK uses FusedLocationAPI to fetch location data.

HyperTrack.enableGNSSMeasurement(boolean enableGNSSMeasurement);

Enable Mock Locations

HyperTrack.enableMockLocations used to enable or disable Mock locations. Mock Locations are DISABLED by default in the SDK.

HyperTrack.enableMockLocations(boolean enableMockLocation);

Check Tracking

Check if the user is active currently i.e. SDK is active for the configured user.

Returns true if the SDK is active for the configured user.

HyperTrack.isTracking();

Get SDK Version

HyperTrack.getSDKVersion used to get current SDK version name.

Returns the VersionName for the SDK casted as a String.

HyperTrack.getSDKVersion();

Utility methods

HyperTrackUtils classes provides the following utility methods:

Method Returns Description
isPublishableKeyConfigured boolean Returns true if HyperTrack SDK's Publishable Key has been configured, false otherwise.
isLocationEnabled boolean Returns true if location is enabled, false otherwise.
getLocationProvider String Returns the device's location provider (one of LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER or LocationManager.PASSIVE_PROVIDER), null if location is disabled.
getLocationAccuracy int Returns the device's location accuracy (one of HyperTrackUtils's constants: LOCATION_MODE_HIGH_ACCURACY, LOCATION_MODE_SENSORS_ONLY or LOCATION_MODE_BATTERY_SAVING), LOCATION_MODE_OFF if location is disabled.
isLocationAccuracyHigh boolean Returns true if device's location accuracy is LOCATION_MODE_HIGH_ACCURACY, false otherwise.
isLocationPermissionAvailable boolean Returns true if location permission is granted to the app, false otherwise.
isInternetConnected boolean Returns true if internet connectivity is available, false otherwise.
isWifiEnabled boolean Returns true if internet connection is WiFi (Un-Metered), false otherwise.
isPlayServicesAvailable boolean Returns true if Google PlayServices is available on the device, false otherwise.

Intents

The SDK provides broadcasts which can be used in your app to determine events invloving user's current location or status. These intents are defined in HyperTrackConstants.

Intent name Description
HT_USER_CURRENT_LOCATION_INTENT Get notified when user's current location is updated
HT_USER_TRACKING_STARTED_INTENT Get notified when user's tracking has started
HT_USER_TRACKING_STOPPED_INTENT Get notified when user's tracking has stopped
HT_ACTION_COMPLETED_INTENT Get notified when any action has completed
ACTION_REMOVED_FROM_TRACKING_NOTIFICATION Get notified when any action has removed from live tracking view

User Current location update intent

Note that this intent is broadcasted only when the SDK is active for the user.

@Override
protected void onResume() {
  super.onResume();
  IntentFilter filter = new IntentFilter(HyperTrackConstants.HT_USER_CURRENT_LOCATION_INTENT);
  LocalBroadcastManager.getInstance(this).registerReceiver(userCurrentLocationReceiver, filter);
}

BroadcastReceiver userCurrentLocationReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent != null) {
      // Get User's current location from Intent Extras
      String userId = intent.getStringExtra(HyperTrackConstants.HT_USER_ID_KEY);
      HyperTrackLocation location = intent.getSerializable(HyperTrackConstants.HT_USER_CURRENT_LOCATION_KEY);
      // Handle User Location update received here
    }
  }
};

@Override
protected void onPause() {
  super.onPause();
  LocalBroadcastManager.getInstance(this).unregisterReceiver(userCurrentLocationReceiver);
}

User tracking started intent

@Override
protected void onResume() {
  super.onResume();
  IntentFilter filter = new IntentFilter();
  filter.addAction(HyperTrackConstants.HT_USER_TRACKING_STARTED_INTENT);
  LocalBroadcastManager.getInstance(this).registerReceiver(userTrackingStartedReceiver, filter);
}

BroadcastReceiver userTrackingStartedReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent != null) {
      String userId = intent.getStringExtra(HyperTrackConstants.HT_USER_ID_KEY);
      // Handle user's tracking started intent here
    }
  }
};

@Override
protected void onPause() {
  super.onPause();
  LocalBroadcastManager.getInstance(this).unregisterReceiver(userTrackingStartedReceiver);
}

User tracking stopped intent

@Override
protected void onResume() {
  super.onResume();
  IntentFilter filter = new IntentFilter();
  filter.addAction(HyperTrackConstants.HT_USER_TRACKING_STOPPED_INTENT);
  LocalBroadcastManager.getInstance(this).registerReceiver(userTrackingStoppedReceiver, filter);
}

BroadcastReceiver userTrackingStoppedReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent != null) {
      String userId = intent.getStringExtra(HyperTrackConstants.HT_USER_ID_KEY);
      // Handle user's tracking stopped intent here
    }
  }
};

@Override
protected void onPause() {
  super.onPause();
  LocalBroadcastManager.getInstance(this).registerReceiver(userTrackingStoppedReceiver, filter);
}

Action Completed intent

Note that this intent is broadcasted only when the SDK is active for the user.

@Override
protected void onResume() {
  super.onResume();
  IntentFilter filter = new IntentFilter(HyperTrackConstants.HT_ACTION_COMPLETED_INTENT);
  LocalBroadcastManager.getInstance(this).registerReceiver(actionCompletedBroadcastReceiever, filter);
}

BroadcastReceiver actionCompletedBroadcastReceiever = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent != null) {
      // Get User's ID and Action ID from Intent Extras
      String userId = intent.getStringExtra(HyperTrackConstants.HT_USER_ID_KEY);
      String actionId = intent.getStringExtra(HyperTrackConstants.HT_ACTION_ID_KEY);
      // Handle action complete intent here
    }
  }
};

@Override
protected void onPause() {
  super.onPause();
  LocalBroadcastManager.getInstance(this).unregisterReceiver(actionCompletedBroadcastReceiever);
}

Action Removed Intent

Note that this intent is broadcasted only when the SDK is active for the user.

[warning] Live-Tracking View

This methods is only useful when you have implemented a live tracking experience view in your app.

@Override
protected void onResume() {
  super.onResume();
  IntentFilter filter = new IntentFilter(HyperTrackConstants.ACTION_REMOVED_FROM_TRACKING_NOTIFICATION);
  LocalBroadcastManager.getInstance(this).registerReceiver(actionRemoveBroadcastReceiver, filter);
}

BroadcastReceiver actionRemoveBroadcastReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent != null) {
      // Get list of removed actions ID from Intent Extras during live tracking view
      ArrayList<String> actionIDs = intent.getStringArrayListExtra(HyperTrackConstants.INTENT_EXTRA_ACTION_ID_LIST);
      // Handle removed action IDs here
    }
  }
};

@Override
protected void onPause() {
  super.onPause();
  LocalBroadcastManager.getInstance(this).unregisterReceiver(actionRemoveBroadcastReceiver);
}

Live Tracking View

Get list of action IDs when action refreshed or action status changes

Need to implement the methods of MapFragmentCallback to get the list of actions IDs when action refreshed or action status changes.

private MapFragmentCallback mapFragmentCallback = new MapFragmentCallback() {
    /**
     * Called when status of any action changes during live tracking.
     *  @param changedStatusActionList is the list of action IDs whose status has changed.
     */
    @Override
    public void onActionStatusChanged(List<String> changedStatusActionList) {
        super.onActionStatusChanged(changedStatusActionList);
    }

    /**
     * Called when action refreshed during live tracking.
     *  @param refreshedActionList is the list of action IDs that are refreshed
     */
    @Override
    public void onActionRefreshed(List<String> refreshedActionList) {
        super.onActionRefreshed(refreshedActionList);
    }
};

Once all this is done, the code snippet would look like as below and once you have the ActionIds to be tracked on the map, your are ready to track actions on the map.

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  ...

  // Initialize Map Fragment added in Activity Layout to getMapAsync
  HyperTrackMapFragment htMapFragment = (HyperTrackMapFragment) getSupportFragmentManager().findFragmentById(R.id.htMapfragment);
  htMapFragment.setHTMapAdapter(new MyMapAdapter(this));
  htMapFragment.setMapFragmentCallback(mapFragmentCallback);

  ...
}

Was this helpful? Yes, thanks! Not really

results matching ""

    No results matching ""