如何在Google Fit Api中区分手动添加的步骤和传感器记录的步骤 [英] How to differentiate between manual added steps and sensor recorded steps in Google Fit Api

查看:90
本文介绍了如何在Google Fit Api中区分手动添加的步骤和传感器记录的步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用Google Fit Api来获取用户的日常操作.但是问题是,用户可以通过添加活动来手动输入步骤.当我检索日常步骤时,Google Fit Api还会返回手动添加的步骤. 有什么方法可以区分手动添加的步骤和传感器记录的步骤.

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.

推荐答案

这是我解决此问题的方法.

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;
        }
    }

第一点->在使用

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.

这篇关于如何在Google Fit Api中区分手动添加的步骤和传感器记录的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆