I tried to read custom height in Google Fit in android using this code:
DataReadRequest readHeightRequest = new DataReadRequest.Builder()
.read(DataType.TYPE_HEIGHT)
.setTimeRange(FIRST_DAY_OF_MONTH_INMS, NOW_INMS, TimeUnit.MILLISECONDS)
.build();
But I got an empty dataset without dataPoint.
According to the documentation of DataType TYPE_HEIGHT :
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 did not see any documentation on the method of setting the time range without the end of time.
Is it possible to have a functional code sample?
[EDIT]
Solution:
use a massive time range. I used the GoogleFit presentation on June 25, 2014 to run:
DataReadRequest readRequest = new DataReadRequest.Builder()
.read(DataType.TYPE_HEIGHT)
.setTimeRange(PresentationOfGoogleFit(June,25,2014), now, TimeUnit.MILLISECONDS)
.setLimit(1)
.build();
And that ... works!;)
[/ EDIT]
Piotr source
share