Fetching Google Fit Data into android application

后端 未结 5 1927
庸人自扰
庸人自扰 2021-01-14 09:08

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

5条回答
  •  无人及你
    2021-01-14 09:53

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

提交回复
热议问题