将距离AGGREGATE_DISTANCE_DELTA插入Google Fit

时间:2016-10-14 18:16:15

标签: android google-fit

从我的应用中我尝试将距离数据插入Google-Fit:

insert(DataType.AGGREGATE_DISTANCE_DELTA, distanceMeters, fromMillis, toMillis);

public void insert(DataType type, float value, long fromMillis, long toMillis) {

  DataSource dataSource = new DataSource.Builder()
    .setType(DataSource.TYPE_RAW)
    .setDataType(type)
    .setAppPackageName(BuildConfig.APPLICATION_ID)
    .build();
  DataSet dataSet = DataSet.create(dataSource);

  DataPoint point = dataSet.createDataPoint();
  point.setTimeInterval(fromMillis, toMillis, TimeUnit.MILLISECONDS);
  point.setFloatValues(value);
  dataSet.add(point);

  Fitness.HistoryApi.insertData(client, dataSet).await(1, TimeUnit.MINUTES);
}

一切顺利 - 授权授权,status.isSuccess()返回true - 但距离从未显示在Google-Fit应用中。

如果我以相同的间隔插入消耗的卡路里,它们会按预期显示:

insert(DataType.AGGREGATE_CALORIES_EXPENDED, kiloCalories, fromMillis, toMillis);

知道AGGREGATE_DISTANCE_DELTA为什么不起作用?

1 个答案:

答案 0 :(得分:1)

尝试在insert函数中明确声明setDataType:

setDataType(DataSource.TYPE_DISTANCE_DELTA)

我认为这类似于Insert Data guide中提到的示例:

// Create a data source
DataSource dataSource = new DataSource.Builder()
.setAppPackageName(this)
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setStreamName(TAG + " - step count")
.setType(DataSource.TYPE_RAW)
.build();

// Create a data set
int stepCountDelta = 950;
DataSet dataSet = DataSet.create(dataSource);
// For each data point, specify a start time, end time, and the data value -- in this case,
// the number of new steps.
DataPoint dataPoint = dataSet.createDataPoint()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS);
dataPoint.getValue(Field.FIELD_STEPS).setInt(stepCountDelta);
dataSet.add(dataPoint);