谷歌抓取拟合数据到Android应用程序 [英] Fetching Google Fit Data into android application

查看:289
本文介绍了谷歌抓取拟合数据到Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何能获取存储在谷歌云适合为特定用户的数据?
我试图用历史API,但正在显示任何数据。然后,我尝试输入一些数据VAI历史API,现在我只能通过历史API不完整的数据,实际上驻留在合适的看到这些数据。

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

数据请求是

  DataReadRequest readRequest =新DataReadRequest.Builder()                .aggregate(DataType.TYPE_STEP_COUNT_DELTA,DataType.AGGREGATE_STEP_COUNT_DELTA)                .bucketByTime(1,TimeUnit.DAYS)
                .setTimeRange(startTime时,结束时间,TimeUnit.MILLISECONDS)
                。建立();


解决方案

根据你的问题,这是很难知道你期待什么,但没有收到。更多详细信息将是有益的。

我猜这是因为飞度返回默认合并的步骤流。基本上,如果两个应用程序都报到使用相同的60分钟内1000步,飞度会认为它们是重复的,为响应合并他们。

尝试失去桶功能,看看你得到的原始步骤。这code为我工作:

 最后DataReadRequest readRequest =新DataReadRequest.Builder()
            .read(DataType.TYPE_STEP_COUNT_DELTA)
            .setTimeRange(startTime时,结束时间,TimeUnit.MILLISECONDS)
            。建立();    DataReadResult dataReadResult =
            Fitness.HistoryApi.readData(mGoogleApiFitnessClient,readRequest).await(1,TimeUnit.MINUTES);    数据集stepData = dataReadResult.getDataSet(DataType.TYPE_STEP_COUNT_DELTA);    INT totalSteps = 0;    为(数据点DP:stepData.getDataPoints()){
        对于(场场:dp.getDataType()getFields()){
            诠释步骤= dp.getValue(场).asInt();            totalSteps + =步骤;        }
    }

How can we get the data stored in google fit cloud for a specific user? I tried using History API but no data is being displayed. Then i tried entering some data vai History api, now I could see these data only via history api not the complete data that actually resides in fit.

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

Data Request is

DataReadRequest readRequest = new DataReadRequest.Builder()

                .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)

                .bucketByTime(1, TimeUnit.DAYS)
                .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                .build();

解决方案

Based on your question, it's hard to know what you're expecting but not receiving. More detail would be helpful.

I'm guessing it's because Fit is returning the default merged stream of steps. Basically, if two apps both report 1,000 steps for the same 60 minute period, Fit will assume that they're duplicative and "merge" them for the response.

Try losing the bucket function and see if you get the raw steps. This code works for me:

    final DataReadRequest readRequest = new DataReadRequest.Builder()
            .read(DataType.TYPE_STEP_COUNT_DELTA)
            .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();

            totalSteps += steps;

        }
    }

这篇关于谷歌抓取拟合数据到Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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