'Google Fit API not returning activities from last 90 days

I'm trying to retrieve the Google Fit activities from the last 90 days, but it is not returning all the activities.

This is the date range:

  • Start date = today - 90 days = Nov/09/2021 00:00:00
  • End date = today = Feb/07/2022 00:00:00

Today I inserted some activities in Nov/09/2021, but the API is not retrieving them. Is there any limit to the time range? I could not find anything in the documentation.

Code sample:

final DataReadRequest req = new DataReadRequest.Builder()
        .aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
        .enableServerQueries()
        .bucketBySession(1, TimeUnit.SECONDS)
        .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
        .build();

Fitness.getHistoryClient(mContext, GoogleSignIn.getLastSignedInAccount(mContext))
        .readData(req)
        .addOnSuccessListener(dataReadResponse -> {
            if (dataReadResponse.getStatus().isSuccess()) {
                // read response data
            }
        });

EDIT: Apparently setTimeRange filters by the activity creation date, not the date I set in Google Fit. I did a test with an account that had activities at November 09 (inserted in the past on that day) and they were returned by the API.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source