这是我使用 google fit API 插入高度的代码。物体高度=160.0F;
DataSource dataSource = new DataSource.Builder()
.setAppPackageName(LoginActivity.this)
.setDataType(DataType.TYPE_HEIGHT)
.setType(DataSource.TYPE_RAW)
.build();
DataSet heightDataSet = new DataSet(dataSource);
DataPoint dataPoint = heightDataSet.createDataPoint().setTimeInterval(Helper.getStartTimeOfDay(Calendar.getInstance().getTimeInMillis()),
Helper.getNow(), TimeUnit.MILLISECONDS);
if (height instanceof Integer) {
dataPoint.getValue(Field.FIELD_HEIGHT).getFormat();
dataPoint = dataPoint.setIntValues((Integer) height);
} else {
dataPoint = dataPoint.setFloatValues((Float) height);
}
heightDataSet.add(dataPoint);
Fitness.HistoryApi.insertData(App.gClient, heightDataSet).setResultCallback(new ResolvingResultCallbacks<Status>(LoginActivity.this, 0) {
@Override
public void onSuccess(Status status) {
}
@Override
public void onUnresolvableFailure(Status status) {
}
});
它给出了错误java.lang.IllegalArgumentException: Field out of range at line heightDataSet.add(dataPoint); 请帮忙。