我正在尝试使用三星健康获取当前的心率。我正在使用三星的 Android 版 SDK,我的代码基于提供的示例来计算步骤。以下是我为下午 6 点所做的一些测试调整代码的方式:
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);
}
所以基本上,问题在于最初的步骤代码测量了一整天的间隔(endTime = startTime + ONE_DAY_IN_MILISECONDS
)。我尝试修改此代码以获得最近 20 秒的心跳平均值,但是当我将 startTime 和 endTime 之间的间隔缩小到低于一小时的间隔时,我检索到的平均值为零。因此,我的问题是:这是获取当前心跳的正确方法吗?如果是这样,我做错了什么或如何实现?