我想在 google fit 中添加我的应用程序的锻炼。所以我现在尝试使用卷发锻炼,就像在官方示例中一样......我的代码是:
// Create a data source
DataSource dataSource = new DataSource.Builder()
.setAppPackageName(this)
.setDataType(DataType.TYPE_WORKOUT_EXERCISE)
.setName(getResources().getString(R.string.app_name))
.setType(DataSource.TYPE_RAW)
.build();
// // Create a data set
DataSet dataSet = DataSet.create(dataSource);
DataPoint curls = DataPoint.create(dataSource);
curls.setTimestamp(now.getTime(), TimeUnit.MILLISECONDS);
curls.getValue(Field.FIELD_EXERCISE).setString(WorkoutExercises.BICEP_CURL);
curls.getValue(Field.FIELD_DURATION).setInt(30000);
curls.getValue(Field.FIELD_REPETITIONS).setInt(10);
curls.getValue(Field.FIELD_RESISTANCE_TYPE).setInt(Field.RESISTANCE_TYPE_DUMBBELL);
curls.getValue(Field.FIELD_RESISTANCE).setFloat(20.0f);
dataSet.add(curls);
Fitness.HistoryApi.insertData(mClient, dataSet)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Data insert was successful!");
} else {
// The deletion will fail if the requesting app tries to delete data
// that it did not insert.
Log.i(TAG, "There was a problem inserting the dataset.");
//TODO store dataset to send it later or make this as a service
}
}
});
问题是插入方法记录成功,但我看到 Google Fit 中没有添加任何数据。我尝试了其他类型的锻炼,比如木板,也达到了同样的效果。但是添加步数是有效的,就像在历史示例中的官方插入中一样,所以我想我错过了与类型锻炼相关的一些内容。有什么线索吗?