简体   繁体   中英

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:

  1. This step value is not the current day's step value. When the day changes the step value does not reset to 0 and continues to increment.
  2. It is not the aggregate of all the previous steps because my cumulative steps are close to 51,000 while currently it shows around 2000.
  3. Everytime I run the code the steps value doesn't reset to 0, so it is taking in some past values.
  4. If I uninstall and reinstall the app, it still starts from 2000.

I would like to know what exactly is dataPoint.getValue(field).asInt() when counting steps?

DataPoint is defined as follows:

  • 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 .

  • 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. 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)

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. In this case, obtain the components of the data point and assign a value to each component individually

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM