gpt4 book ai didi

android - 以与 Google Fit 应用程序相同的方式获取 Google Fit 历史记录(Google Fit 自动记录的 Activity )

转载 作者:行者123 更新时间:2023-12-03 13:26:12 26 4
gpt4 key购买 nike

我正在努力显示与 Google Fit 应用程序相同的 Activity 历史记录。我在 session 方面做得很好,但我无法正确掌握自动记录的 Activity 。就像示例中的这两个顶级行走一样。
enter image description here
我认为一切都归结为DataReadRequest建成。我得到的最接近的是:

DataReadRequest.Builder()
.aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
.bucketByActivitySegment(5, TimeUnit.MINUTES)
.setTimeRange(dateFrom.millis, dateTo.millis, TimeUnit.MILLISECONDS)
.build()
故意排除少于 5 次步行。结果相似,但结果略有不同。持续时间和千卡减少约 20%。有时它真的很疯狂,把 Activity 切成小块。我在 Google Fit 中进行了 2 次步行,最终在我的应用程序中进行了 4 次步行,这与 Google Fit 的 2 次不相上下。我试图反编译 Google Fit 应用程序以“借用”请求设置,但该应用程序被很好地混淆了。 :)
有人实现了吗?

最佳答案

我现在在 google fit 服务中没有任何数据来达到什么目的
你需要。
但是,我这样做是为了在每个练习中检索 bpm。

 /**
* Returns a List of exercise with time period and their heart rate via callback
*/
public void getHeartRatePerExercise(Date date , ExerciseHeartRateListener exerciseHeartRateListener) {

Calendar calendar = Calendar.getInstance();

calendar.setTime(date);
calendar.set(Calendar.MILLISECOND, 1);
calendar.set(Calendar.SECOND, 1);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR_OF_DAY, 0);

long startTime = calendar.getTimeInMillis();

calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.SECOND, 59);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.HOUR_OF_DAY, 23);

long endTime = calendar.getTimeInMillis();


DataReadRequest readRequest =
new DataReadRequest.Builder()
.aggregate(DataType.TYPE_HEART_RATE_BPM, DataType.AGGREGATE_HEART_RATE_SUMMARY)
.bucketByActivityType(1, TimeUnit.MINUTES)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();


Task<DataReadResponse> readResponse = getHistoryClient(activity, googleSignIn).readData(readRequest);

readResponse.addOnSuccessListener(response -> {
List<Bucket> buckets = response.getBuckets();
List<Workout> workouts = new ArrayList<>();

for (Bucket bucket : buckets) {

String activityName = bucket.getActivity();
Timestamp start = new Timestamp(bucket.getStartTime(TimeUnit.MILLISECONDS));
Timestamp end = new Timestamp(bucket.getEndTime(TimeUnit.MILLISECONDS));

if (!(activityName.equals("still") || activityName.equals("unknown"))) {
List<DataSet> dataSets = bucket.getDataSets();

for (DataSet dataSet : dataSets) {
for (DataPoint dataPoint : dataSet.getDataPoints()) {
float min = dataPoint.getValue(Field.FIELD_MIN).asFloat();
float max = dataPoint.getValue(Field.FIELD_MAX).asFloat();
float avg = dataPoint.getValue(Field.FIELD_AVERAGE).asFloat();
HeartRate hr = new HeartRate(min, max, avg);
Workout workout = new Workout(activityName, start, end, hr);

workouts.add(workout);

}
}
}
}
exerciseHeartRateListener.getHR(workouts);
}).addOnFailureListener(response -> {
exerciseHeartRateListener.getHR(new ArrayList<>());
});

}
心率
public class HeartRate {

private float min;
private float max;
private float avg;

public HeartRate(float min, float max, float avg) {
this.min = min;
this.max = max;
this.avg = avg;
}

public float getMin() {
return min;
}


public float getMax() {
return max;
}


public float getAvg() {
return avg;
}

}
锻炼
public class Workout {

private String name;
private Timestamp start;
private Timestamp end;
private HeartRate heartRate;

public Workout(String name, Timestamp start, Timestamp end, HeartRate heartRate) {
this.name = name;
this.start = start;
this.end = end;
this.heartRate = heartRate;
}

public String getName() {
return name;
}

public Timestamp getStart() {
return start;
}

public Timestamp getEnd() {
return end;
}

public HeartRate getHeartRate() {
return heartRate;
}

}
界面:
 public interface ExerciseHeartRateListener {
void getHR(List<Workout> workouts);
}

关于android - 以与 Google Fit 应用程序相同的方式获取 Google Fit 历史记录(Google Fit 自动记录的 Activity ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64314121/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com