Tracking data

If a required tracker type is available on the watch device, track data with:

protected final void trackPpgContinuous() {
    // Start PPG Continuous data tracking.
    HealthTracker ppgContinuousTracker = null;
    ppgContinuousTracker = 
        healthTracking.getHealthTracker(HealthTrackerType.PPG_CONTINUOUS);
    ppgContinuousTracker.setEventListener(trackerListener);
}

An event for tracking data is retrieved in:

  • HealthTracker.TrackerEventListener.onDataUpdated(List<DataPoint> list)

Receiving data occurs until the event listener is unset.

private final HealthTracker.TrackerEventListener trackerListener = 
    new HealthTracker.TrackerEventListener() {
    
    @Override
    public void onDataReceived(List<DataPoint> list) {
    }

    @Override
    public void onError(HealthTracker.TrackerError error) {
        // Error occurs..
    }

    @Override
    public void onFlushCompleted() {
        // Flushing data is completed.
    }
};

If you get SDK_POLICY_ERROR, it indicates that your app’s SDK policy was not downloaded yet.

Flushing data

If a watch’s display is off, Health Platform provides batched tracking data. flush() gives the collected data instantly.

protected final void flushHeartRate() {
    // Flushing data gives collected data instantly.
    heartRateContinuousTracker.flush();
}

For example, tracking continuous heart rate normally gives 600 samples every 10 minutes.

  • If flush() is called when 25 samples have been gathered, a DataPoint list in onDataUpdated() gives only 25 samples.
  • After getting the flush result, onDataUpdated() again provides another 600 samples after a 10 minites period.

Stop tracking

If your app doesn’t need to track data anymore, unset the registered event listener with:

protected final void stopTracking() {
    // Unsetting the event listener stops tracking data.
    ppgContinuousTracker.unsetEventListener();
}