从我的应用程序中,我尝试将距离数据插入到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不工作吗?
发布于 2016-10-17 07:55:11
尝试在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);https://stackoverflow.com/questions/40049646
复制相似问题