1
閱讀營養數據有延遲嗎?我插入的營養數據,我想讀他們,但數據點的尺寸仍然等於0 ...營養數據谷歌適合
我插入這樣的數據:
long now = System.currentTimeMillis();
DataSource nutritionSource = new DataSource.Builder()
.setAppPackageName(getApplicationContext().getPackageName())
.setType(DataSource.TYPE_RAW)
.setDataType(DataType.TYPE_NUTRITION)
.build();
DataSet dataSet = DataSet.create(nutritionSource);
DataPoint dataPoint = DataPoint.create(nutritionSource);
dataPoint.setTimestamp(now, TimeUnit.MILLISECONDS);
dataPoint.getValue(Field.FIELD_FOOD_ITEM).setString(name_food);
dataPoint.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_CALORIES, calorie_food);
dataPoint.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_SUGAR,sugar_food);
dataPoint.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_TOTAL_FAT,fat_food);
dataPoint.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_PROTEIN,protein_food);
dataPoint.getValue(Field.FIELD_MEAL_TYPE).setInt(Field.MEAL_TYPE_UNKNOWN);
dataSet.add(dataPoint);
然後,我想看他們這樣的:
DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_NUTRITION, DataType.AGGREGATE_NUTRITION_SUMMARY)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();
// Invoke the History API to fetch the data with the query and await the result of
// the read request.
DataReadResult dataReadResult =
Fitness.HistoryApi.readData(mClient, readRequest).await(1, TimeUnit.MINUTES);
if(dataReadResult.getStatus().isSuccess()){
Log.i("TAG","isSuccess to read nutrition data");
if(dataReadResult.getDataSet(DataType.TYPE_NUTRITION).getDataPoints().size() > 0){
Log.i("TAG","calorie : "+dataReadResult.getDataSet(DataType.TYPE_NUTRITION).getDataPoints().get(0).getValue(Field.FIELD_CALORIES));
}
}
我想獲得當天的所有數據點,並與他們的工作,但我不知道如何?
感謝,
卡邁勒