4

I tried to read user's height in Google Fit in android with this code :

 DataReadRequest readHeightRequest = new DataReadRequest.Builder()
            .read(DataType.TYPE_HEIGHT)
            .setTimeRange(FIRST_DAY_OF_MONTH_INMS, NOW_INMS, TimeUnit.MILLISECONDS)
            .build();

But I only got a empty dataset with no dataPoint.

According to the DataType TYPE_HEIGHT documentation:

the start time should not be set.

So I tried to remove :

.setTimeRange(FIRST_DAY_OF_MONTH_INMS, NOW_INMS, TimeUnit.MILLISECONDS)

-> CRASH

java.lang.IllegalStateException: Invalid start time: 0
            at com.google.android.gms.internal.jx.a(Unknown Source)
            at com.google.android.gms.fitness.request.DataReadRequest$Builder.build(Unknown Source)

And I didn't see any documentation of method to set time range without endtime.

Is it possible to have a functional sample of code ?

[EDIT]

Solution : use a massive time range. I used the presentation of GoogleFit on June 25, 2014 for starting time :

DataReadRequest readRequest = new DataReadRequest.Builder()
                .read(DataType.TYPE_HEIGHT)
                .setTimeRange(PresentationOfGoogleFit(June,25,2014), now, TimeUnit.MILLISECONDS)
                .setLimit(1)
                .build();

And it....works ! ;)

[/EDIT]

Piotr
  • 238
  • 2
  • 12
  • Add the logcat please – TooCool Feb 12 '15 at 17:37
  • 1
    you should add a solution as an answer, and even accept it so people who visit this question will see it clearly. – cyborg86pl Apr 14 '15 at 20:06
  • I am attempting to do the same thing with TYPE_WEIGHT and his solution does not work for me. I have 2 weight entries I input yesterday, and nothing comes back with the request, even if I use a massive time range. – Andrew Apr 29 '15 at 18:15
  • @Andrew : I use this and it's working : `DataReadRequest readRequest = new DataReadRequest.Builder() .read(DataType.TYPE_WEIGHT) .setTimeRange(PresentationOfGoogleFit(June,25,2014), now, TimeUnit.MILLISECONDS) .setLimit(1) .enableServerQueries() .build();` (hope it helps) – Piotr Apr 30 '15 at 08:35
  • @Piotr It doesn't work for me. In `ResultCallback`'s `onResult`, the size of `readDataResult.getBuckets().size()` is 0. – Andrew Apr 30 '15 at 19:09

0 Answers0