How to differentiate between manual added steps and sensor recorded steps in Google Fit Api

ⅰ亾dé卋堺 提交于 2019-12-02 08:56:05

问题


I am using Google Fit Api in my project to get user's daily steps. But the problem is, user can enter the steps manually by adding the activities. And when i retrieve the daily steps, Google Fit Api also returns the steps which were added manually. Is there any way to differentiate between manually added steps and sensor recorded steps.


回答1:


Basically, the example given in the Google Fit documentation states that you can get the base daily steps total of your device by using this method.

Your app can record the user's step count by using the Recording API to create a subscription to the DataType.TYPE_STEP_COUNT_CUMULATIVE data type

In your case, you are getting the aggregate data which is a combination of the sensor recorded steps and the data extracted using the History API.

Try to check out the essential Google Fit API's that you will be needing:

  • Sensors API
  • Recording API
  • History API
  • Sessions API
  • Goals API
  • Bluetooth Low Energy API
  • Config API



回答2:


This is how i solved this issue.

   final DataReadRequest readRequest = new DataReadRequest.Builder()
            .read(googleFitUtils.getEstimatedSteps())
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .build();

    DataReadResult dataReadResult =
            Fitness.HistoryApi.readData(mGoogleApiFitnessClient, readRequest).await(1, TimeUnit.MINUTES);

    DataSet stepData = dataReadResult.getDataSet(DataType.TYPE_STEP_COUNT_DELTA);

    int totalSteps = 0;

    for (DataPoint dp : stepData.getDataPoints()) {
        for(Field field : dp.getDataType().getFields()) {
            int steps = dp.getValue(field).asInt();
            if (!"user_input".equals(dp.getOriginalDataSource().getStreamName()))
                totalSteps += steps;
        }
    }

First Point - > Before i was getting the total steps using

Fitness.HistoryApi.readDailyTotal

which returns one data point with total daily steps. Second Point - > Then i changed the way to get the daily steps using

Fitness.HistoryApi.readData

It returns array of data points with the chunks of daily steps. Each data point has a property of

dp.getOriginalDataSource().getStreamName()

which returns you the type, either steps were recorded by sensor or it was a use input. That's how you can filter the user input steps to avoid steps hack in your application.



来源:https://stackoverflow.com/questions/54093789/how-to-differentiate-between-manual-added-steps-and-sensor-recorded-steps-in-goo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!