这就是让我失望的东西。我正在使用Google Fit网站和文档中的示例代码。我从一个样本中得到的主要修正是我创建了一个月的时间跨度而不是一周。
DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();
Fitness.HistoryApi.readData(this.getGoogleClient(), readRequest)
.setResultCallback(new ResultCallback<DataReadResult>() {
@Override
public void onResult(DataReadResult result) {
if (listener != null) {
RangedStepsReport report = null;
if (result.getStatus().isSuccess()) {
Log.d(TAG, "Google Fit: Report obtained");
java.text.DateFormat dateFormat = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT);
report = new RangedStepsReport(startTime, endTime);
//
for (Bucket b : result.getBuckets()) {
Log.i(TAG, "Bucket: " + b.getBucketType());
Log.i(TAG, "Activity: " + b.getActivity());
Log.i(TAG, "StartDate: " + dateFormat.format(b.getStartTime(TimeUnit.MILLISECONDS)));
Log.i(TAG, "EndDate: " + dateFormat.format(b.getEndTime(TimeUnit.MILLISECONDS)));
Log.i(TAG, "Activity: " + b.getSession());
for (DataSet ds : b.getDataSets()) {
Log.i(TAG, "\tData set:" + ds.getDataType());
Log.i(TAG, "\tSource:" + ds.getDataSource());
for (DataPoint dp : ds.getDataPoints()) {
Log.i(TAG, "\tData point:");
Log.i(TAG, "\t\tType: " + dp.getDataType().getName());
Log.i(TAG, "\t\tStart: " + dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
Log.i(TAG, "\t\tEnd: " + dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)));
for (Field field : dp.getDataType().getFields()) {
Log.i(TAG, "\t\t\tField: " + field.getName() + " Value: " + dp.getValue(field));
}
}
}
}
//
} else {
Log.d(TAG, "Google Fit: Report NOT obtained!");
}
}
}
});
这应该是从GoogleFit获取步骤列表的最佳方式,无论设备有多少步进传感器。
然后,我在同一天获得了不同的值,用于我在白天进行的不同查询(执行完全相同的代码)。
/<pack.....> I/GoogleFitUtil: Bucket: 1
/<pack.....> I/GoogleFitUtil: Activity: in_vehicle
/<pack.....> I/GoogleFitUtil: StartDate: 3/5/16
/<pack.....> I/GoogleFitUtil: EndDate: 4/5/16
/<pack.....> I/GoogleFitUtil: Activity: null
/<pack.....> I/GoogleFitUtil: Data set:DataType{com.google.step_count.delta[steps(i)]}
/<pack.....> I/GoogleFitUtil: Source:DataSource{derived:Application{com.google.android.gms::null}:aggregated:DataType{com.google.step_count.delta[steps(i)]}}
/<pack.....> I/GoogleFitUtil: Data point:
/<pack.....> I/GoogleFitUtil: Type: com.google.step_count.delta
/<pack.....> I/GoogleFitUtil: Start: 3/5/16
/<pack.....> I/GoogleFitUtil: End: 4/5/16
/<pack.....> I/GoogleFitUtil: Field: steps Value: 6097
/<pack.....> I/GoogleFitUtil: Bucket: 1
/<pack.....> I/GoogleFitUtil: Activity: in_vehicle
/<pack.....> I/GoogleFitUtil: StartDate: 4/5/16
/<pack.....> I/GoogleFitUtil: EndDate: 5/5/16
/<pack.....> I/GoogleFitUtil: Activity: null
/<pack.....> I/GoogleFitUtil: Data set:DataType{com.google.step_count.delta[steps(i)]}
/<pack.....> I/GoogleFitUtil: Source:DataSource{derived:Application{com.google.android.gms::null}:aggregated:DataType{com.google.step_count.delta[steps(i)]}}
/<pack.....> I/GoogleFitUtil: Data point:
/<pack.....> I/GoogleFitUtil: Type: com.google.step_count.delta
/<pack.....> I/GoogleFitUtil: Start: 4/5/16
/<pack.....> I/GoogleFitUtil: End: 5/5/16
/<pack.....> I/GoogleFitUtil: Field: steps Value: 22162
然后是相同的查询
/<pack.....> I/GoogleFitUtil: Bucket: 1
/<pack.....> I/GoogleFitUtil: Activity: in_vehicle
/<pack.....> I/GoogleFitUtil: StartDate: 3/5/16
/<pack.....> I/GoogleFitUtil: EndDate: 4/5/16
/<pack.....> I/GoogleFitUtil: Activity: null
/<pack.....> I/GoogleFitUtil: Data set:DataType{com.google.step_count.delta[steps(i)]}
/<pack.....> I/GoogleFitUtil: Source:DataSource{derived:Application{com.google.android.gms::null}:aggregated:DataType{com.google.step_count.delta[steps(i)]}}
/<pack.....> I/GoogleFitUtil: Data point:
/<pack.....> I/GoogleFitUtil: Type: com.google.step_count.delta
/<pack.....> I/GoogleFitUtil: Start: 3/5/16
/<pack.....> I/GoogleFitUtil: End: 4/5/16
/<pack.....> I/GoogleFitUtil: Field: steps Value: 5994
/<pack.....> I/GoogleFitUtil: Bucket: 1
/<pack.....> I/GoogleFitUtil: Activity: in_vehicle
/<pack.....> I/GoogleFitUtil: StartDate: 4/5/16
/<pack.....> I/GoogleFitUtil: EndDate: 5/5/16
/<pack.....> I/GoogleFitUtil: Activity: null
/<pack.....> I/GoogleFitUtil: Data set:DataType{com.google.step_count.delta[steps(i)]}
/<pack.....> I/GoogleFitUtil: Source:DataSource{derived:Application{com.google.android.gms::null}:aggregated:DataType{com.google.step_count.delta[steps(i)]}}
/<pack.....> I/GoogleFitUtil: Data point:
/<pack.....> I/GoogleFitUtil: Type: com.google.step_count.delta
/<pack.....> I/GoogleFitUtil: Start: 4/5/16
/<pack.....> I/GoogleFitUtil: End: 5/5/16
/<pack.....> I/GoogleFitUtil: Field: steps Value: 22181
通知有一天,田地往往会上升,有一天田地往往会下降。这与我注射病症的时间有关吗?
谢谢和问候