【问题标题】:Google Fit: What is DataType Floor of Google Fit.Google Fit:什么是 Google Fit 的 DataType Floor。
【发布时间】:2016-07-25 11:43:28
【问题描述】:

我想从 Google Fit 获得价值底线。但是我没有找到关于楼层的数据类型。

这是我的代码。

private void setDailyFloors() {
PendingResult<DailyTotalResult> dailyFloors = Fitness.HistoryApi.readDailyTotal(mClient, DataType.TYPE_ACTIVITY_SAMPLE);
dailyFloors.setResultCallback(new ResultCallback<DailyTotalResult>() {
  @Override
  public void onResult(@NonNull DailyTotalResult dailyTotalResult) {
    if (dailyTotalResult.getStatus().isSuccess()) {
      DataSet totalSet = dailyTotalResult.getTotal();
      if (totalSet != null) {
        floor = totalSet.isEmpty() ? 0 : totalSet.getDataPoints().get(0).getValue(Field.FIELD_ACTIVITY).asInt();
      }
    }
  }
});

}

【问题讨论】:

    标签: java android google-fit


    【解决方案1】:

    我在Google Fit documentation 中没有看到任何与数据类型楼层相关的内容,可能这是一种自定义数据类型。

    只需查看此link 即可了解有关自定义数据类型的更多信息。

    若要首次创建自定义数据类型,请使用ConfigApi.createCustomDataType 方法:

    // 1. Build a request to create a new data type
    DataTypeCreateRequest request = new DataTypeCreateRequest.Builder()
    // The prefix of your data type name must match your app's package name
    .setName("com.app.custom_data_type")
    // Add some custom fields, both int and float
    .addField("field1", Field.FORMAT_INT32)
    .addField("field2", Field.FORMAT_FLOAT)
    // Add some common fields
    .addField(Field.FIELD_ACTIVITY)
    .build();
    
    
    // 2. Invoke the Config API with:
    // - The Google API client object
    // - The create data type request
    PendingResult<DataTypeResult> pendingResult =
    ConfigApi.createCustomDataType(mClient, request);
    
    
    // 3. Check the result asynchronously
    // (The result may not be immediately available)
    pendingResult.setResultCallback(
    new ResultCallback<DataTypeResult>() {
    @Override
    public void onResult(DataTypeResult dataTypeResult) {
    // Retrieve the created data type
    DataType customType = dataTypeResult.getDataType();
    // Use this custom data type to insert data in your app
    // (see other examples)
    ...
    }
    }
    );
    

    只需阅读以上链接以了解更多信息。包括,如何 检索您的自定义数据类型以及如何创建自定义数据类型的数据点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-26
      • 2017-05-25
      • 2016-08-14
      相关资源
      最近更新 更多