我正在学习 Android,我的任务是使用 Google Fit steps API 检索步数数据。但是,我不断收到“任务尚未完成”错误。我不知道
这是我那部分的代码:
private List<Fitness> readHistoryDataFromGoogle() {
DataReadRequest readRequest = createDataReadRequest();
Task<DataReadResponse> response = com.google.android.gms.fitness.Fitness.getHistoryClient(this, GoogleSignIn.getLastSignedInAccount(this)).readData(readRequest);
DataReadResponse responses = response.getResult();
List <Fitness> fitnessItems = parseFitness(responses);
return fitnessItems;
}
private List<Fitness> parseFitness(DataReadResponse dataReadResponse) {
List<com.example.mentalhealthapp.Fitness> fitnessItems = new ArrayList<>();
for (Bucket bucket : dataReadResponse.getBuckets()) {
for (DataSet set : bucket.getDataSets()) {
for (DataPoint dataPoint : set.getDataPoints()) {
int numSteps = dataPoint.getValue(Field.FIELD_STEPS).asInt();
long startDateTime = dataPoint.getStartTime(TimeUnit.MILLISECONDS);
long endDateTime = dataPoint.getEndTime(TimeUnit.MILLISECONDS);
fitnessItems.add(new com.example.mentalhealthapp.Fitness(numSteps, startDateTime, endDateTime));
}
}
}
return fitnessItems;
}
非常感谢您的帮助!
繁星点点滴滴
相关分类