Android SDK reference

Methods

User status methods

APIs in HyperTrack class can be used to the get user's current status.

String userId = HyperTrack.getUserId();
boolean isUserTracking = HyperTrack.isTracking();
Method Returns Description
getUserId String Returns unique id of the currently configured user in the SDK, null if no user is configured.
isTracking String Returns true if the SDK is active for a user, false otherwise.

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

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

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

results matching ""

    No results matching ""