[英]Interpretation of step value obtained in onDataPoint in google fit
I have the following code to get the step count 我有以下代码来计算步数
@Override
public void onDataPoint(DataPoint dataPoint) {
for (final Field field : dataPoint.getDataType().getFields()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
steps = dataPoint.getValue(field).asInt();
Log.d(TAG, "Steps: " + steps);
}
});
}
}
What I have found out: 我发现了什么:
I would like to know what exactly is dataPoint.getValue(field).asInt()
when counting steps? 我想在计算步骤时知道
dataPoint.getValue(field).asInt()
究竟是什么?
DataPoint is defined as follows: DataPoint定义如下:
Represents a single data point in a data type's stream from a particular data source . 表示来自特定数据源的数据类型流中的单个数据点。 A data point holds a value for each field, a timestamp and an optional start time.
数据点包含每个字段的值,时间戳和可选的开始时间。 The exact semantics of each of these attributes is specified in the documentation for the particular data type, which can be found in the appropriate constant in DataType .
每个属性的确切语义在特定数据类型的文档中指定,可以在DataType中的相应常量中找到。
A data point can represent an instantaneous measurement, reading or inputted observation, as well as averages or aggregates over a time interval. 数据点可以表示瞬时测量,读取或输入观察,以及一段时间间隔内的平均值或聚合。 Check the data type documentation to determine which is the case for a particular data type.
检查数据类型文档以确定特定数据类型的情况。
DataPoints always contain one value for each the data type field. DataPoints始终为每个数据类型字段包含一个值。 Initially, all of the values are unset.
最初,所有值都未设置。 After creating the data point, the appropriate values and timestamps should be set.
创建数据点后,应设置适当的值和时间戳。
public Value getValue (Field field) 公共值getValue(字段字段)
Returns the value holder for the field with the given name. 返回具有给定名称的字段的值持有者。 This method can be used both to query the value and to set it.
此方法既可用于查询值也可用于设置值。
Create data points of custom data types: 创建自定义数据类型的数据点:
// Create a data point for a data source that provides
// data of type "com.app.custom_data_type" (created above)
DataPoint dataPoint = DataPoint.create(myDataSource);
// Set values for the data point
// This data type has two custom fields (int, float) and a common field
dataPoint.getValue(0).setInt(mField1IntValue);
dataPoint.getValue(1).setFloat(mField2FloatValue);
dataPoint.getValue(Field.FIELD_ACTIVITY).setInt(mActivityValue);
When you create custom data types that contain both int
and float
fields, you can't use the DataPoint.setFloatValues()
and DataPoint.setIntValues()
methods for those fields. 创建包含
int
和float
字段的自定义数据类型时,不能对这些字段使用DataPoint.setFloatValues()
和DataPoint.setIntValues()
方法。 In this case, obtain the components of the data point and assign a value to each component individually 在这种情况下,获取数据点的组件并分别为每个组件分配值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.