0

I found some strange behavior in Fitness request that I can't explain. I create in parallel two requests, one to History like:

DataReadRequest readRequest = new DataReadRequest.Builder()
        .aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
        .bucketByTime(1, TimeUnit.HOURS)
        .enableServerQueries()
        .setTimeRange(startTime, System.currentTimeMillis(), TimeUnit.MILLISECONDS)
        .build();

Fitness.getHistoryClient(this, GoogleSignIn.getLastSignedInAccount(this))
                .readData(readRequest) ... add listeners

And another to Sessions like:

SessionReadRequest request = new SessionReadRequest.Builder()
            .setTimeInterval(startTime, System.currentTimeMillis(), TimeUnit.MILLISECONDS)
            .read(DataType.TYPE_ACTIVITY_SEGMENT)
            .readSessionsFromAllApps()
            .enableServerQueries()
            .build();

    Fitness.getSessionsClient(this, GoogleSignIn.getLastSignedInAccount(this))
            .readSession(request) ... add listeners

My startTime is generated like this:

Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.HOUR_OF_DAY, -1);
long startTime = cal.getTimeInMillis();

And I get results in my log for History:

DataSet{d:activity.summary:gms:aggregated[
RawDataPoint{[3, 3560719, 1]@[1552377379822000000, 1552380940541000000](4,5)}, 
RawDataPoint{[7, 38157, 1]@[1552377341665000000, 1552377379822000000](4,5)}]}

And for Sessions:

Session []

I see in log that I have two activity types (3 - Still (not moving) and 7 - Walking) in my fit by last hour, but how to explain that I don't get it in Sessions request?

  • When I try to make startTime one week ago I get results in Sessions request.
Vadim Eksler
  • 865
  • 9
  • 24

1 Answers1

1

Here's a related SO post wherein the data from History API is not matched with Fit app. And as per the documentation, SessionsClient provides the entry point for creating and managing Sessions of user activity in Google Fit. A Session represents a time interval with associated metadata. Sessions do not contain fitness data themselves. You can think of sessions as metadata objects with information that helps you query data from the fitness store later.

Jessica Rodriguez
  • 2,899
  • 1
  • 12
  • 27