I am using Samsung Health SDK for Android in order to obtain in streaming the heart rate beat from the wristband. The first thing I did was to download the example to count steps. Then, in the method to read the steps, I have modified the code to read the heartbeat. The code I am using for this purpose is the following:
HealthDataResolver resolver = new HealthDataResolver(mStore, null);
// Set time range from start time of today to the current time
long startTime = 16 * 60 * 60 * 1000;
long endTime = startTime + 2 * 60 * 60 * 1000;
HealthDataResolver.Filter filter = HealthDataResolver.Filter.and(
HealthDataResolver.Filter.greaterThanEquals(HealthConstants.HeartRate.START_TIME, startTime),
HealthDataResolver.Filter.lessThanEquals(HealthConstants.HeartRate.END_TIME, endTime));
HealthDataResolver.ReadRequest request = new ReadRequest.Builder()
.setDataType(HealthConstants.HeartRate.HEALTH_DATA_TYPE)//.setDataType(HealthConstants.StepCount.HEALTH_DATA_TYPE)
.setProperties(new String[] {HealthConstants.HeartRate.HEART_RATE})
.setLocalTimeRange(
HealthConstants.StepCount.START_TIME,
HealthConstants.StepCount.TIME_OFFSET,
startTime, endTime)
.setFilter(filter)
.build();
try {
resolver.read(request).setResultListener(mListener);
} catch (Exception e) {
Log.e(MainActivity.APP_TAG, "Getting step count fails.", e);
}
This is the snippet I was using for getting the heart beat at 16h. It retrieves the average heart beat from 14 to 16h. Using this logic, I tried to narrow the window’s time to the last 10 seconds in order to obtain the heart beat in streaming. The problem is that when I reduce this window to lower than one hour, it retrieves a zero value. Therefore, I am not sure if this is the best way to achieve this and, if so, how can I do it in order to obtain in my app the heartbeat in streaming.
Thanks.