7

I am trying to get GoogleFit data with buckets of 15 minutes for the last 2 weeks. But for some reason the call to the HistoryApi does never finish, even if I wait some minutes. When using 1 hour buckets, it returns pretty fast. Are there any limitations I just didn't see?

My plan would be to get 15 minute buckets for the last year or so, but if not even 2 weeks work that's going to be a problem...

What I have so far: I set up my GoogleApi Client like this:

        mClient = new GoogleApiClient.Builder(mContext)
            .addApi(Fitness.SENSORS_API)
            .addApi(Fitness.HISTORY_API)
            .addScope(new Scope(FITNESS_ACTIVITY_READ))
            .addConnectionCallbacks(
                    new GoogleApiClient.ConnectionCallbacks() {
                        @Override
                        public void onConnected(Bundle bundle) {
                            fetchHistoryData();
                        }

                        @Override
                        public void onConnectionSuspended(int i) {
                            // Here I'll handle that case
                        }
                    }
            )
            .enableAutoManage(mContext, 0, new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(ConnectionResult result) {
                    //Here I'll handle that case
                }
            })
            .build();

And then I try to fetch data like this:

    final DataReadRequest readRequest = new DataReadRequest.Builder()
            .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
            .aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)
            .bucketByTime(1, TimeUnit.HOURS)
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .build();

    Fitness.HistoryApi.readData(mClient, readRequest).setResultCallback(new ResultCallback<DataReadResult>() {
        @Override
        public void onResult(@NonNull DataReadResult dataReadResult) {
            handleGoogleFitData(dataReadResult);
        }
    });

which works perfectly fine, but when I go ahead and change the bucket time to .bucketByTime(15, TimeUnit.MINUTES) my onResult will never get called. I also noticed the same when having 1 hour intervals and going back 1 year.

Is this a limitation of Google-Fit? I at least didn't find any documentation about a limit like this...

I also sometimes get a callback of a query fast, sometimes it just won't ever return. Any ideas about that?

Georg
  • 3,119
  • 2
  • 27
  • 60
  • What does your code look like that doesn't work? Please provide a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) that demonstrates the issue. – abielita Mar 18 '17 at 06:33
  • @abielita I updated my question... thx – Georg Mar 20 '17 at 07:16
  • If you filter the logs with "Fitness" text, you can see the error. Actually fetching any data more than around 500kb doesn't work. You will get either deadObject exception or TransactionTooLargeException. This is because Google Fit is passing data through IPC, which has limitation. – PK Gupta Apr 10 '20 at 16:30

0 Answers0