1

我有一个从三星健康读取健康数据并浏览它的安卓应用程序。我添加了 Samsung Health sdk 版本 1.4.0 并开始使用 HealthDataResolver.ReadRequest 获取数据,以读取不同的数据值,例如总步数、距离和活动时间。我可以从 HealthConstants.StepCount 读取步数和距离,但我找不到与存储在 Samsung Health 中作为活动时间值的值相关的任何键。现在我的问题是如何获取活动时间分钟以在我的应用程序中浏览它。

    public void readSteps(){

    HealthDataResolver resolver = new HealthDataResolver(mStore, null);

    HealthDataResolver.Filter filter = null;
    if(mReadDataRequest.getStartTime() != 0.0)
        filter = HealthDataResolver.Filter.greaterThanEquals(HealthConstants.StepCount.START_TIME, mReadDataRequest.getStartTime());

    HealthDataResolver.ReadRequest request = new HealthDataResolver.ReadRequest.Builder()
            .setDataType(HealthConstants.StepCount.HEALTH_DATA_TYPE)
            .setTimeBefore(Calendar.getInstance().getTimeInMillis())
            .setFilter(filter)
            .build();

    try {
        resolver.read(request).setResultListener(result -> {
            ArrayList<BaseHealthKit> stepCounts = null;
            try {
                for (HealthData data : result) {
                    int count = data.getInt(HealthConstants.StepCount.COUNT);
                    double distance = data.getDouble(HealthConstants.StepCount.DISTANCE);
                    String startTime = data.getString(HealthConstants.StepCount.START_TIME);
                    String endTime = data.getString(HealthConstants.StepCount.END_TIME);
                    float burnedCalorie = data.getFloat(HealthConstants.StepCount.CALORIE);

                    if (stepCounts == null)
                        stepCounts = new ArrayList<>();

                    StepCount stepCount = new StepCount();
                    if (startTime != null)
                        stepCount.setStartTime(Long.parseLong(startTime));
                    if (endTime != null)
                        stepCount.setEndTime(Long.parseLong(endTime));
                    stepCount.setCount(count);
                    stepCount.setDistance(distance);
                    stepCount.setmBurnedCalories(burnedCalorie);
                    stepCounts.add(stepCount);
                }
            } finally {
                result.close();
            }

            if (mReadDataListener != null)
                mReadDataListener.onSucceedReading(stepCounts);
        });
    } catch (Exception e) {
        Log.e(TAG, "Getting sleep data fails.", e);
    } finally {
        disconnect();
    }
}
4

0 回答 0